4

I have a Maven repository that has jar files I want to use locally on other projects. What is the best way to download those jar files from the Maven repo.

I went to http://mvnrepository.com/ but the jar files do not work in my build. I would like to have is the Maven build jar files, but I am not able to save them from my project in Netbeans.

Is there a way to download all the files within Maven repository?

Brandon Wilson
  • 4,462
  • 7
  • 60
  • 90

4 Answers4

8

There's probably thousands of jar files in maven central, so I wouldn't try to download all of them.

Generally, if you want to use jars found in maven repositories, you may want to start a maven project yourself; configure your pom.xml to require those dependencies, and they'll be downloaded automatically.

Most java IDEs have maven support or a maven plugin.

-- EDIT --

Here's a really quick pom.xml example from maven's website:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

If you're using eclipse, you'll probably want to m2e plugin to handle most of this for you. Plus, it will link the javadoc to those jars as well. :)

WhyNotHugo
  • 9,423
  • 6
  • 62
  • 70
3

Why don't you try using Maven instead? With Maven you're able to automatically manage your dependencies easily.

It's really simple. Please check this Maven in 5 minutes so you can begin with it successfully. Any doubts, please let me know.

-- EDIT --

As soon as you learn some main concepts, like dependencies, you can simple start your projects with the following command:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

After that, you can simply import to the most used IDEs like Eclipse, using:

mvn eclipse:eclipse
axcdnt
  • 14,004
  • 7
  • 26
  • 31
  • I'd suggest using the eclipse m2e plugin. It'll make updating the proyect a little easier, and will like the javadoc/source for dependencies so they can be seen on the autocompletition. – WhyNotHugo Jul 30 '12 at 14:56
2

The tool mvn2get (https://github.com/groboclown/mvn2get) will download published Maven artifacts suitable for use in a local repository. This includes the POM files, checksum files, and signature files, as well as able to search through dependencies.

It allows for a one-line execution to download the files:

$ mvn2get.py -d my-local-repo-dir --resolve log4j:log4j:1.2.17

I wrote this script based on a similar need to download into a local repository.

Groboclown
  • 119
  • 1
  • 3
1

The obvious answer is to suggest that you consider building your code using Maven. This will give you native support for the Maven Central repository.

But... I sense that you just want to download the files you need to a local directory? In that case I'd suggest using the Apache ivy command-line.

Example

The files you want are listed in a ivy.xml file. For example:

<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    <info organisation="com.myspotontheweb" module="demo"/>

    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.6" conf="default"/>
        <dependency org="junit" name="junit" rev="4.10" conf="default"/>
    </dependencies>

</ivy-module>

And ivy can populate a local "lib" directory as follows:

java -jar ivy.jar -retrieve "lib/[artifact].[ext]" -ivy ivy.xml

The advantage of this approach is that ivy can download the additional transitive dependencies of the modules you've specified:

$ find lib -type f
lib/commons-lang.jar
lib/junit.jar
lib/hamcrest-core.jar

Note:

  • hamcrest-core is a depedency of junit.
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185