Updated April 17, 2023
Introduction to Maven Assembly Plugin
Maven assembly plugin is used to combine all project output into a single archive distributed file, this file already contains the documentation, modules, dependencies and other files related to the project. We can easily build the distribution of our project, using the prefabricated assembly descriptors we can build our project easily. The maven assembly descriptors is handling the many operations related to project like project artefact, packaging and document generation in a single file. Our project is providing its own descriptor and we assume that it has a high level of control on dependencies.
What is Maven Assembly Plugin?
It is nothing but the group of files which contains the dependencies, project directory and other files which was clubbed in archive format. The maven project is nothing but the single JAR file which was contains swing application and console application.
Below is the format which was used to create distribution of project.
- war: It will create project in war file format.
- dir: It will create the project directory format.
- jar: It will create project in jar file format.
- tar.xz or txz: It will create project in tar.xz file format.
- Zip: It will create project in zip file format.
- tar: It will create project in tar file format.
- tar.gz or tgz: It will create project in tar.gz file format.
- tar.snappy: It will create project in tar.snappy file format.
- tar.bz2 or tbz2: It will create project in tar.bz2 file format.
- Archive manager format.
For using assembly plugin in maven project we need to choose the write assembly descriptor. In assembly descriptor will play very important role. After choosing the write assembly descriptor we need to configure the assembly plugin i.e. pom.xml. After configuring assembly plugin we need to run the assembly single mvn in our project. We can also generate our own assembly for our project.
Below are the apache version available for the general use.
- Version 2.0.x
- Version 2.1.x
- Version 2.2.x
- Version 2.3.x
- Version 2.4.x
- Version 2.5.x
- Version 2.6.x
- Version 3.0.x
- Version 3.1.x
- Version 3.2.x
- Version 3.3.x
In below example we can see that how we can configure to the existing application. In below example we are configuring the plugin to the existing assembly maven project.
For configuring we need to follow below steps.
1. Open the existing maven project.
- To configure the first step is to open the existing maven project.
In below example we are opening the assembly project.
File -> open project from file system -> select the project
2. After opening the maven project, we need to open the pom.xml file and need to add the assembly plugin into it.
Code:
<plugin> --- start of assembly plugin section.
<artifactId> /* start of artifactid section.
maven-assembly-plugin /* name of plugin */ </artifactId> -- end of artifactid section.
<configuration> -- start of assembly configuration section.
<descriptorRefs> -- start of descriptorRefs section.
<descriptorRef>j/* start of second descriptorRefs. */ jar-with-dependencies /* descriptorRefs name */ </descriptorRef> -- end of descriptorRefs section.
</descriptorRefs> -- end of second descriptorRefs section.
<archive> -- start of archive section
<manifest> -- Start of manifest section
<mainClass> /* start of main class */ com.example.AssemblyApplication /* name of main class */ </mainClass> -- end of main class.
</manifest> -- end of manifest section
</archive> -- end of archive section
</configuration> -- end of configuration section.
<executions> -- start of executions section.
<execution> -- start of second execution section.
<id>make-assembly</id> -- Set the id name of maven assembly section.
<phase>package</phase> -- select the package.
<goals> -- start of goals section.
<goal>single</goal>
</goals> -- end of goal section.
</execution> -- end of execution section.
</executions> -- end of execution section.
</plugin> -- End of assembly plugin.
Output:
3. After adding the assembly plugin code build the assembly plugin, after building the assembly plugin run the application.
- The main goal of assembly in java application is single. The single goal is used to create all assemblies.
- We need to specify id at the time of creating assembly plugin. ID is very important section.
Advantages and Disadvantages of Maven Assembly Plugin
Given below are the advantages and disadvantages mentioned:
Advantages:
- We are adding maven assembly plugin in pom.xml so it will adding all the dependency automatically which was required for the project.
- We can easily build our project into jar, war and zip file after adding maven assembly plugin in our project.
- Using maven assembly plugin in maven project we can easily convert our project into different environment.
- After converting maven project into different environment we have no need to handle the dependency like builds, injection and processing.
- After implementing it we can easily run our project after building the same.
- It is easy to add another dependency plugin to our project.
Disadvantages:
- We need to install maven to run the plugin of maven assembly, without installing of maven we cannot run the maven plugin.
- To use the plugin we need to add the code into the pom.xml file.
- We cannot run our application without adding the code into the pom.xml file.
- To run the maven application using assembly plugin first we need to build the assembly plugin.
- Without building the assembly plugin we cannot use in our project.
Conclusion
It is used to combine all project output into single distributed file. We can convert our project output in tar, zip and war file format using it. It is very useful and important to combine all project output in single file.
Recommended Articles
We hope that this EDUCBA information on “Maven Assembly Plugin” was beneficial to you. You can view EDUCBA’s recommended articles for more information.