How to Create a Fat Jar with Maven

A fat jar or uber jar is a jar that contains the classes of your current project as well as all of the classes on which it depends. For example, if your application requires Joda-Time, your jar file will contain all the classes of your current project, as well as all the classes of Joda-Time. This helps solve the problem of having to organize and provide numerous jars for your program’s classpath.

Creating this fat jar with Maven is actually very easy. There are several plugins that do this, but my favorite is the Maven Shade Plugin. This opinion is mostly due to Maven Shade’s simplicity, community, and documentation. Creating a fat jar with Maven Shade can be as easy as adding the text below to the pom.xml file in your Maven project.

By default, two jars will be created by executing the package phase. The ‘original’ jar, which will only contain the classes of your current project, and the ‘shaded’ jar which will contain all of your projects dependencies.

Other Maven plugins that can be used to create a fat jar are the Maven Assembley Plugin and the One-Jar Plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">