Download all files under a groupId from Maven Repository through command or Java program

2.2k views Asked by At

Our project is using Nexus Repository Manager to store all the jars. Along with the jar I see that under a group there are other files like pom.xml, .md5, .sha1 file. I am in need of these files at our server startup. Is there a way that I can download all the files under a particular group programatically using Java/Curl command/mvn dependency command at runtime?

2

There are 2 answers

5
Bui Anh Tuan On

Maven also uses local repository for caching. The default location is Default: ${user.home}/.m2/repository. You can check this setting in file settings.xml under [maven_dir]/conf/.
To update dependencies, use -U option. i.e. mvn clean install -U
Do not forget setting nexus repo inside pom.xml file http://maven.apache.org/pom.html#Repository

0
Swapnil Jaju On

I could do it with the simple approach. Club all the xmls into a JAR/ZIP file and upload that zip file under my groupId to the Maven Repository. Then programatically use CURL/WGET to download the zip and unzip the contents of that zip file (using any available utility) at runtime.

  1. Put all XMLs under a zip file.
  2. Use mvn deploy to load this zip file to my Maven Nexus Repo.
  3. Then Programatically during runtime, download the zip file using simple weburl call to that ZIP file.
  4. Use ZIP4J or any other library to unzip the contents to my required output folder
  5. Pick files from this server when needed during the flow.

Hope its helpful to someone somewhere sometime. :)