Skip to content

Instantly share code, notes, and snippets.

@thomashartm
Created June 1, 2019 18:27
Show Gist options
  • Save thomashartm/c126ba0bbc4dd5781564162064b30d42 to your computer and use it in GitHub Desktop.
Save thomashartm/c126ba0bbc4dd5781564162064b30d42 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment