Packaging a jar with all dependencies using maven

To package a jar, containing all dependency class files, it is quite easy:

In your pom.xml, within the plugins section, add the following:


<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

Call: mvn package, this will produce two jars, one with dependencies and one without.

Leave a comment