Home > Maven3 > How to create an all-inclusive jar using Maven2

How to create an all-inclusive jar using Maven2

When using maven2 you can create an executable jar file that contains all dependencies necessary at runtime using the following config:

<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptionRef>jar-with-dependencies</descriptionRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>your.Mainclass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>

Run “mvn assembly:assembly” to create the jar with included dependencies. If you want to integrate this in your regular build run use the following configuration:

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

You might have noticed that we include the “attached” goal in the package fase instead of the “assembly” goal we called earlier. This is because the assembly goal would trigger the package fase a second time, while the attached goal is equal to the assembly goal but assumes the package fase has already been completed.

Advertisements
Categories: Maven3 Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: