Skip to content

Instantly share code, notes, and snippets.

@ppatierno
Created March 31, 2016 12:23
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ppatierno/aa616e1cedaed1d51bbd18663a53bab1 to your computer and use it in GitHub Desktop.
Save ppatierno/aa616e1cedaed1d51bbd18663a53bab1 to your computer and use it in GitHub Desktop.
Packaging an executable fat JAR with Apache Maven
Three ways to create an executable and fat JAR with Maven :
maven-jar-plugin (it doesn't add dependencies inside the final JAR, they have to be in the classpath)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>{your.package.main.class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
maven-assembly-plugin (it adds all dependecies inside the final fat JAR)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>{your.package.main.class}</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
maven-shade-plugin (it adds all dependecies inside the final fat JAR and executes shading)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>{your.package.main.class}</mainClass>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
@xaveng
Copy link

xaveng commented Nov 25, 2016

Thank you 👍

@arteika
Copy link

arteika commented Jun 29, 2018

nice!

@jason4zhu
Copy link

awesome, thanks~

@KonstantinSpase
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment