In Java How to Create .jar / .tar.gz / .zip Archive file using maven-assembly-plugin? Maven and Enterprise Project Tutorial

Last updated
App Shah
Crunchify » Java and J2EE Tutorials » In Java How to Create .jar / .tar.gz / .zip Archive file using maven-assembly-plugin? Maven and Enterprise Project Tutorial

Maven is pretty amazing. With so many plugins it is one of the Best Java Build tool in the market right now.

I use it in all of my projects and heavily depends on it. Build possibilities are endless. Some time back I’ve written different tutorials on so many other maven plugins and in this one we will go over maven-assembly-plugin.

Maven Assembly Plugin relies on the provided assembly descriptors to dictate its execution.

Here is a list of previous maven plugins tutorial:

Do you have any of below questions? This tutorial will work for it too.

  • How to create a jar file with Maven?
  • How to use maven to create jar file with dependencies
  • Use pom.xml to create jar
  • Best way to create maven jar without dependencies
  • How to create maven jar including dependencies

Let’s get started with maven-assembly-plugin


Create New Maven project in Eclipse environment. Name it as CrunchifyMavenBuildPlugins. If you have existing Dynamic Web Project or Java Project then using these steps you could convert project to maven project. After converting project to Maven you should see pom.xml file generated which we need for this tutorial.

Here is my project structure. I’m using my existing project which has total 8 java files under /src/com/crunchify/tutorials package.

maven assembly plugin - Crunchify Tutorial


Open your project’s pom.xml file add new <plugin></plugin> mainly line 28 to 38.

<project xmlns="" xmlns:xsi=""





Create new file crunchify.xml and put it under /src/com/crunchify/assembly package. We have referred this file already in above pom.xml file.


Here we are exporting our project into 3 different <formats>

  • tar.gz
  • zip
  • tar

<directory> tag shows that – get everything under package src/com/crunchify/tutorial and put it under crunchify-output folder which is mentioned under <outputDirectory> tag.

If you want to include everything like /src or /resource folder contents then you could use below below different variations:

  1. <directory>src/com/crunchify/tutorial</directory>
  2. <directory>src</directory> : everything under src folder
  3. <directory>resources</directory> : everything under resources folder
  4. <directory>/</directory> : everything


Right click on project CrunchifyMavenBuildPlugins => Run As => Maven build

Maven Right Click and Clean Build - Crunchify
  • Provide Goals as clean assembly:assembly
  • Click Apply
  • Click Run
Create assembly using eclipse build command


You should see BUILD SUCCESS message on console.

[INFO] --- maven-assembly-plugin:2.5.3:assembly (default-cli) @ CrunchifyMavenBuildPlugins ---
[INFO] Reading assembly descriptor: src/com/crunchify/assembly/crunchify.xml
[INFO] Building tar: /Users/crunchifyjavatutorials/CrunchifyMavenBuildPlugins/target/CrunchifyMavenBuildPlugins-0.0.1-SNAPSHOT-bundle.tar.gz
[INFO] Building zip: /Users/crunchifyjavatutorials/CrunchifyMavenBuildPlugins/target/
[INFO] Building tar: /Users/crunchifyjavatutorials/CrunchifyMavenBuildPlugins/target/CrunchifyMavenBuildPlugins-0.0.1-SNAPSHOT-bundle.tar
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.719 s


NOTE: you don’t have to perform this step.

tarLongFileMode for maven deployment descriptor - maven assembly plugin

Are you getting this error? If you see this error message while building assembly then you have to add below line to pom.xml file.


I got above error on my 1st attempt. So already added tarLongFileMode to above pom.xml file.


Now how to verify? Please go to your project’s target folder and run below command to see your .tag.gz file contents.

bash-3.2$ tar zxvf CrunchifyMavenBuildPlugins-0.0.1-SNAPSHOT-bundle.tar.gz

maven assembly plugin - verify result - crunchify

Let me know if you have any question and face any issue running this.

1 thought on “In Java How to Create .jar / .tar.gz / .zip Archive file using maven-assembly-plugin? Maven and Enterprise Project Tutorial”

Leave a Comment