Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

maven

Is there a way to download dependencies from a pom.xml file to a specified folder in java? I'm able to run maven command from java and I got download messages, but I don't know where maven stores these libraries? How can I download these dependencies to a specific folder?

like image 915
Feras Odeh Avatar asked Oct 12 '11 15:10

Feras Odeh


People also ask

Where does POM xml download dependencies?

Drop to a terminal in your project folder (where your pom. xml is located). Maven Dependency Plugin will download dependencies (for example, JAR files) into the folder target/dependency .

Where does Maven store downloaded jars?

The Local Repository Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository. Usually, this directory is named . m2.

How do I force Maven to download dependencies from remote repository?

Force maven to fetch dependencies from the remote repository while building the project. We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository.


2 Answers

Take a look at maven's dependency plugin, specifically the copy-dependencies goal. The usage section describes how to do exactly what you want.

To do it from the command line just do:

$ mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR 

Add this to exclude the transitive or inner dependencies:

-DexcludeTransitive=true

like image 68
sblundy Avatar answered Sep 16 '22 17:09

sblundy


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

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

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

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

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 
like image 35
Anthony O. Avatar answered Sep 16 '22 17:09

Anthony O.