HowTo

How to use maven shade plugin to create fat jar

In this post I will show how to use maven's shade plugin to create fat jar also known as a uber jar or jar with dependencies that contains not only a Java program, but embeds its dependencies as well. Here I have use maven version 3.2.4. Below is the full configuration I used to create fat jar for projects. I hope you find it helpful. 

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test.MyClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin> NOTE: <mainClass> Fully qualified name of your main class </mainClass>.
A fully-qualified class name in Java contains the package that the class originated from.
An example of this is java.util.Arraylist.