Maven packaging type
1 Overview
Packaging type is an important aspect of any Maven project. It specifies the type of artifacts produced by the project. Typically, the building generates jar
, war
, pom
or other executable files.
Maven provides many default packaging types, and also provides the flexibility to define custom packaging types.
In this tutorial, we will delve into Maven's packaging types. First, let's take a look at the build life cycle in Maven. Then, we will discuss each type of packaging, what they represent and their impact on the project life cycle. Finally, we will see how to define a custom packaging type.
2.Default packaging type
Maven provides a number of default package types, including jar
, war
, ear
, pom
, rar
, ejb
and maven-plugin
. Each packaging type follows a build life cycle composed of phases. Usually, each stage is a series of goals and performs specific tasks.
At a specific stage, different packaging types may have different goals. For example, in jar
the packaging stage of the packaging type, maven-jar-plugin
the jar target will be executed . On the contrary, for war
projects, maven-war-plugin
the war goals are executed in the same phase.
2.1. jar
Java archive files (or jar
) are one of the most popular types of packaging. Projects with this type of packaging will generate an extension .jar
which may include pure Java classes, interfaces, resources and metadata files.
jar
Some default targets are bound to the build phase:
resource:
resources
translater:
compile
resource:
testResources
translater:
testCompile
surefire:
test
Jar:
jar
Install:
install
deploy:
deploy
Without delay, let us define jar
the packaging type of a project:
<packaging>jar</packaging>
If nothing is specified, Maven assumes that the packaging type isjar.
2.2. war
In short, a web application archive file (or war
file) contains all the files related to the web application. It may include Java Servlet, JSP, HTML page, deployment descriptor and related resources. Overall, the war
jar
same target binding, but with one exception- war
the packaging stage has different targets, ie war
.
Undoubtedly, jar
and war
is the most popular type of packaging in the Java community. The detailed difference between the two may be an interesting reading.
Let's define the packaging type of the web application:
<packaging>war</packaging>
Other types of packaging ejb
, par
and rar
also has a similar life cycle, but each package has a different packaging goals.
ejb: ejb or par: par or rar: rar
2.3. ear
Enterprise application archive files (ie ear
) are compressed files that contain J2EE applications. It consists of one or more modules.These modules can be Web modules (packaged as war
files) or EJB modules (packaged as jar
files), or these two modules.
ear
jars
And wars
a superset need an application server to run the application, and war
requires only a Web container or webserver can be deployed. For Java developers, the aspects that distinguish web servers from application servers and what those popular servers are in Java are important concepts.
ear
The default target binding:
ear:
generate-application-xml
resource:
resources
ear:
ear
Install:
install
deploy:
deploy
This is how we define the type of packaging for such items:
<packaging>ear</packaging>
2.4. pom
Among all packaging types, it pom
is the simplest one. It helps to create aggregators and parent projects.
Aggregators or multi-module projects will assemble sub-modules from different sources . These submodules are regular Maven projects and follow their own build life cycle. modules
There are all references to submodules under the element.
The parent project allows you to define the inheritance relationship between POMs. The parent POM shares certain configurations, plugins and dependencies and their versions. Most elements from the parent are inherited by their children-exceptions include artifactId
, name
and prerequisites
.
Because there are no resources to process, and no code to compile or test. Therefore, the artifacts of the pom project will be generated by itself instead of generating any executable files.
Let's define the packaging type of a multi-module project:
<packaging>pom</packaging>
Such a project has the simplest life cycle, which includes only two steps: install
and deploy
.
2.5. maven-plugin
Maven provides various useful plug-ins. However, it may happen that the default plugins are not enough. In this case, the tool can flexibly create Maven plug-ins based on project requirements.
To create a plug-in, set the packaging type of the project:
<packaging>maven-plugin</packaging>
maven-plugin
The life cycle of is similar to jar
the life cycle, with two exceptions:
Plug-in:
descriptor
bind to the generate-resources stagePlug-in:
addPluginArtifactMetadata
added to the packaging stage
For such projects, maven-plugin-api
dependencies are required .
2.6. ejb
Enterprise Java Bean (or ejb
) helps to create scalable distributed server-side applications. EJB usually provides the business logic of the application. A typical EJB architecture consists of three components: Enterprise Java Bean (EJB), EJB container and application server.
Now, let us define the packaging type of the EJB project:
<packaging>ejb</packaging>
ejb
Packaging types also have a jar
similar life cycle to packaging, but the packaging goals are different. Packaging objective of such projects is the EJB: ejb
.
ejb
Package type projects maven-ejb-plugin
to implement life cycle goals. Maven provides support for EJB 2 and 3. If the version is not specified, the default version 2 is used.
2.7. rar
A resource adapter (or rar
) is an archive file used as an effective format for deploying a resource adapter to an application server. Basically, it is a system-level driver that connects Java applications to an enterprise information system (EIS).
This is the declaration of the packaging type of the resource adapter:
<packaging>rar</packaging>
Each resource adapter archive consists of two parts: one contains source code jar
files and one is used as a deployment descriptorra.xml
Similarly, the life cycle phases are the same one jar
or war
the packaging with one exception: during the **package**
phase execution rar
, it is **maven-rar-plugin**
packaged and archived by a target ** . **
3.Other packaging types
So far, we have studied the various packaging types that Maven provides by default. Now, let's imagine that we want our project to generate an extension. .zip
In this case, the default packaging type will not help.
Maven also provides more packaging types through plugins. With the help of these plugins, we can define custom packaging types and their build life cycle. Some of these types are:
msi
rpm
tar
tar.bz2
tar.gz
tbz
zip
To define a custom type, we must define it packaging
type
and in the life cycle for phases
.
this, please in the src/main/resources/META-INF/plexus
catalogcomponents.xml
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>zip</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<phases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<package>com.baeldung.maven.plugins:maven-zip-plugin:zip</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
</configuration>
</component>
So far, Maven knows nothing about our new packaging type and its life cycle. To make it visible, let's pom
extensions
set the project to true
:
<plugins>
<plugin>
<groupId>com.baeldung.maven.plugins</groupId>
<artifactId>maven-zip-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
Now, the item will be available for scanning, and the system will also search plugins
and compnenets.xml
files.
In addition to all these types, Maven also provides many other packaging types through external projects and plugins. For example, nar
(native archive), swf
and swc
are the packaging types for projects that produce Adobe Flash and Flex content. For this type of project, we need a plugin that defines a custom packaging and a repository that contains the plugin.
4. in conclusion
In this article, we looked at the various packaging types available in Maven. In addition, we are familiar with what these types represent and how they differ in the life cycle. Finally, we also learned how to define custom packaging types and custom default build life cycles.
order lipitor 10mg generic & lt;a href="https://lipiws.top/"& gt;buy lipitor 20mg for sale& lt;/a& gt; lipitor 20mg generic
Hkpfzb
2024-03-08