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

JavaMaven

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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

Solution 3 - Java

Add something similar to 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 perform the copy. Combine this with the assembly plugin and you can package everything into a self contained archive for distribution.

Solution 4 - Java

Maven stores all of these in it's local Maven2 repository. By default, it will store them in your user home directory under a directory called repository.

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

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

Solution 5 - Java

  1. Go to this site: http://jar-download.com/online-maven-download-tool.php

  2. Insert the Maven dependencies XML

  3. Download the jar files as a ZIP.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFeras OdehView Question on Stackoverflow
Solution 1 - JavasblundyView Answer on Stackoverflow
Solution 2 - JavaAnthony O.View Answer on Stackoverflow
Solution 3 - JavaAmarView Answer on Stackoverflow
Solution 4 - JavafrankjlView Answer on Stackoverflow
Solution 5 - JavaUwe334View Answer on Stackoverflow