Compile Java project with dependencies into single JAR file

To create one single JAR file that contains all required JAR dependencies, you will need to use maven-assembly-plugin to create a custom JAR bundle.

Here is an example usage of the plugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>MyProject</finalName>
<outputDirectory>${project.basedir}/../output</outputDirectory>
<descriptorRefs>jar-with-dependencies</descriptorRefs>
</configuration>
<executions>
<execution>
<id>build-jar-with-dependencies</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
Share Comments