How to use Maven pom to download jar files only to a specific directory?

Is there a way to load the dependencies from the pom.xml file into the specified folder in java? I can run the maven command from java and I have downloadable messages, but I don’t know where maven stores these libraries? How to download these dependencies to a specific folder?

+53
java maven
Oct 12 '11 at 15:07
source share
5 answers

Take a look at the maven dependency plugin, specifically the copy-dependencies target. This section describes how to do exactly what you want.

To do this from the command line, simply do:

 $ mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR 
+87
Oct 12 2018-11-11T13
source share
+4
May 15 '16 at 12:57
source share

Add something like the following to pom.xml:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <configuration> <outputDirectory> ${project.build.directory} </outputDirectory> </configuration> </plugin> 

Then run mvn clean dependency:copy-dependencies to execute the copy. Combine this with the build plugin , and you can pack everything into a standalone archive for distribution.

+3
Dec 16 '15 at 9:05
source share

Maven stores all this in its local Maven2 repository. By default, it will save them in the user's home directory in a directory called a repository.

You can use the maven-dependency-plugin target called copy to take all the dependencies of your project and put them in a folder.

http://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html

+2
Oct 12 2018-11-11T13
source share

As explained here , you can use the maven-dependency- plugin: get one for this.

For example, if you want to download org.apache.hive:hive-common:2.1.1 in your local folder, do the following:

 mvn dependency:get -Ddest=./ -Dartifact=org.apache.hive:hive-common:2.1.1 

If you want to download the latest version 3.0.0-SNAPSHOT:tar.gz version of com.orientechnologies:orientdb-community-gremlin from the snapshot repository https://oss.sonatype.org/content/repositories/snapshots , do the following:

 mvn dependency:get -Ddest=./ -DremoteRepositories=sonatype-nexus-snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dartifact=com.orientechnologies:orientdb-community-gremlin:3.0.0-SNAPSHOT:tar.gz 
0
Nov 24 '17 at 15:34
source share



All Articles