Monday, 3 September 2012

Maven Dependency Download

Heres a quick hack to download jars and their dependencies from a maven repository, without a proper maven project or any other dependency management tools. For times when you just want the damn jars!All you need is maven installed.

Here is a template pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>temp.temp</groupId>
    <artifactId>temp</artifactId> 
  <version>1</version>
  <name>temp</name>
  <dependencies>
        
        <!-- Put your dependencies here -->
        <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>3.8</version>
        </dependency>
            
  </dependencies>
</project>

Put your maven style dependencies under the dependencies tag. In the examlple above you can see that I have specified the apache poi dependency. The dependency tags for other jars can be found here: http://mvnrepository.com/. 

Now open terminal (command prompt) and navigate to where you have saved the pom.xml file. 

Run the following command 
mvn dependency:copy-dependencies

This will download the dependencies, as well as its dependencies(transitively). The jars will be located under target/dependency

No comments:

Post a Comment