Maven Assembly Plugin Example

Maven Assembly Plugin Example

Handling build with maven is easy task where just you need to add dependencies in your pom.xml. Apart from this maven provides many more advance feature which can be use based on your project requirement. On of the mandatory requirement of any project is package the project in deploy on servers. As you know that any project can have multiple files which contains dependencies jars, properties files, xml files, bat files, sh files and many more. So if you want deploy you project on the server you will need all of these files. In this example I will show you how you can put all files together using maven assembly plugin.

To better understand I will create sample project with multiple module. Please see below parent and child module maven project structure and you can also download this project from Java Honk github here:

  • Parent maven project:

Maven Assembly Plugin Example

  • ChildModule1

Maven Assembly Plugin Example

  • ChildModule2

Maven Assembly Plugin Example

  • As you see above project structure we have create MavenAssemblyPlugin project which is parent project and to better understand two child project MavenAssemblyPluginChild1 and MavenAssemblyPluginChild2 also got created. To assemble this project you will have to add below maven assembly plugin to pom.xml and if you are using parent child module maven project then you don’t need to add assembly plugin to every project just add below to your parent pom.xml also please notice we have added maven-dependency-plugin which will all dependency jar into lib folder which ofcourse will be available in project target/lib directory and from here assembly plugin will pickup jar and put in zip, tar and tar.gz. file.

Parent pom.xml:

  • Parent assembly.xml – We will assemble project related file in three different format which is zip, tar and tar.gz and what file will be included you could see below assembly.xml file:

  • Separately add assembly.xml in your child project as you would like to pack file differently in every project. MavenAssemblyPluginChild1 project assembly.xml:

  • MavenAssemblyPluginChild2 project assembly.xml:

  • Now right click parent pom.xml and click maven install as shown below. This will start build, clean, verifiy and install jar of the project and if all goes successful you will message on the console:

Maven Assembly Plugin Example

Maven Assembly Plugin Example

  • Now if you refresh your project target folder you will below. For example I am including only MavenAssemblyPluginChild2 project generated file as this will be available for all projects including parent project:

Maven Assembly Plugin Example

  • If you extract any of the file you will see below structure:

Maven Assembly Plugin Example

  • For more information of maven assembly plugin please visit maven site here

download Download Project:  MavenAssemblyPlugin

Leave a Reply

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