Wednesday, July 8, 2015

How to create a custom Maven packaging

Distributing software made in Java is pretty standard, either a jar, a war or an ear format is used. However, it is not uncommon the need for other formats. Cases like applications being distributed in a tar or zip format, with some scripts, are often found.

Maven provides an easy mechanism for packaging applications in the standard formats and when a custom packaging is required, the Assembly plugin is the most common option. Though it is a good solution, it tends to overload the build specification with its configuration and the descriptor file. Also, it is not easy to share or reuse among similar projects.

A custom packaging is an appropriate alternative for this cases, as all the magic can be encapsulated inside a Maven plugin, and the pom would look like:


<packaging> my-custom-packaging </packaging>


Lets create a custom packaging, called jzip for packaging the application in a zip file with a start script.