In the Part 1 of this, we had seen how to use the appassembler plugin to create a distribution tar. In this increment, we will see how to use the Maven assembly plugin to create a uber jar or fat jar. A uber jar or fat jar is a single jar having the contents of all the dependencies needed for the project. Again, we will be using the maven-distribution-example as reference. This project would need the project rmi-service-api to compile. We have created a profile called uber-jar:
uber-jar org.apache.maven.plugins maven-assembly-plugin 2.6 create-uber-jar package single jar-with-dependencies assemble-all package single src/assembly/uber-jar-assembly-descriptor.xml
The assembly plugin uses a pre-fabricated descriptor called jar-with-dependencies. This would condense all dependencies into the single fat jar.
Note there are 2 executions. The first one creates the uber jar and the second one takes that uber jar and the readme.txt and creates a zip file. It does this by using the below assembly descriptor (uber-jar-assembly-descriptor.xml):
uber-jar zip false ${project.basedir}/src/static / readme.txt ${project.build.directory} / ${project.name}-${project.version}-jar-with-dependencies.jar
The uber jar can be generated by:
mvn clean package -P uber-jar
The sources can be found here: https://github.com/paawak/blog/tree/master/code/maven-ant-assembly-example