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

2022-08-31 12:23:07

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?


答案 1

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


答案 2

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

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

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

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

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

推荐