English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Maven POM

POM (Project Object Model, project object model) is the basic working unit of a Maven project, which is an XML file containing basic project information, used to describe how the project is built, declare project dependencies, and so on.

When executing a task or target, Maven will look for the POM in the current directory. It reads the POM, retrieves the required configuration information, and then executes the target.

The following configurations can be specified in the POM:

  • Project dependencies

  • Plugins

  • Execution target

  • Project build profile

  • Project version

  • List of project developers

  • Related email list information

Before creating a POM, we first need to describe the project group (groupId), the unique ID of the project.

<project xmlns = "http://maven.apache.org/POM/4.0.0"
    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance
    xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
    <!-- Model version -->
    <modelVersion>4.0.0</modelVersion>/modelVersion>
    <!-- The unique identifier of a company or organization, and the path generated during configuration is also generated from it, such as com.companyname.project-group, Maven will place the jar package of this project in the local path:/com/companyname/project-group -->
    <groupId>com.companyname.project-group</groupId>
 
    <!-- The unique ID of the project, there may be multiple projects under a groupId, which are distinguished by artifactId -->
    <artifactId>project</artifactId>
 
    <!-- Version number -->
    <version>1.0</version>
</project>

All POM files must have a project element and three required fields: groupId, artifactId, and version.

NodeDescription
projectThe root tag of the project.
modelVersionThe model version needs to be set to 4.0.
groupIdThis is the identifier of the project group. It is usually unique in an organization or project. For example, a banking organization com.companyname.project-The group owns all projects related to banking.
artifactIdThis is the identifier of the project. It is usually the name of the project. For example, consumer banking. groupId and artifactId together define the location of the artifact in the repository.
version

This is the version number of the project. In the artifact repository, it is used to distinguish different versions. For example:

com.company.bank:consumer-banking:1.0
com.company.bank:consumer-banking:1.1

Parent (Super) POM

The parent (Super) POM is Maven's default POM. All POMs inherit from a parent POM (whether the parent POM is explicitly defined or not). The parent POM contains some default settings that can be inherited. Therefore, when Maven finds that it needs to download dependencies from the POM, it will go to the default repository configured in the Super POM, http://repo1.maven.org/maven2 Download it.

Maven uses effective pom (Super pom plus the project's own configuration) to execute related goals, which helps developers make as few configurations as possible in pom.xml, of course, these configurations can be overwritten.

Use the following command to view the default configuration of Super POM:

mvn help:effective-pom

Next, we create the directory MVN/project, create a pom.xml in this directory, as follows:

<project xmlns = "http://maven.apache.org/POM/4.0.0"
    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance
    xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
    <!-- Model version -->
    <modelVersion>4.0.0</modelVersion>/modelVersion>
    <!-- The unique identifier of a company or organization, and the path generated during configuration is also generated from it, such as com.companyname.project-group, Maven will place the jar package of this project in the local path:/com/companyname/project-group -->
    <groupId>com.companyname.project-group</groupId>
 
    <!-- The unique ID of the project, there may be multiple projects under a groupId, which are distinguished by artifactId -->
    <artifactId>project</artifactId>
 
    <!-- Version number -->
    <version>1.0</version>
</project>

Enter MVN in the command console/project directory, execute the following command:

C:\MVN\project>mvn help:effective-pom

Maven will start processing and display the effective-pom.

[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:36 min
[INFO] Finished at: 2018-09-05T11:31:28+08:00
[INFO] Final Memory: 15M/149M
[INFO] ------------------------------------------------------------------------

The result of Effective POM is displayed in the console as shown, after inheritance and interpolation, the configuration takes effect.

<?xml version="1.0" encoding="UTF-8"?>
<!-- ================================================================= -->
<!--                                                                   -->
<!-- Generated by Maven Help Plugin on 2012-07-05T11:41:51             -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/           -->
<!--                                                                   -->
<!-- ================================================================= -->
 
<!-- ================================================================= -->
<!--                                                                   -->
<!-- Effective POM for project                                         -->
<!-- 'com.companyname.project-group:project-name:jar:1.0'              -->
<!--                                                                   -->
<!-- ================================================================= -->
 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 h
ttp://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>/modelVersion>
  <groupId>com.companyname.project-group</groupId>
  <artifactId>project</artifactId>
  <version>1.0</version>
  <build
    <sourceDirectory>C:\MVN\project\src\main\java</sourceDirectory>
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\MVN\project\src\test\java</testSourceDirectory>
    <outputDirectory>C:\MVN\project\target\classes</outputDirectory>
    <testOutputDirectory>C:\MVN\project\target\test-classes</testOutputDirectory>
    <resources
      <resource
        <mergeId>resource</mergeId>-0</mergeId>
        <directory>C:\MVN\project\src\main\resources</directory>/directory>
      </resource>
    </resources>
    <testResources
      <testResource
        <mergeId>resource</mergeId>-1</mergeId>
        <directory>C:\MVN\project\src\test\resources</directory>/directory>
      </testResource>
    </testResources>
    <directory>C:\MVN\project\target</directory>/directory>
    <finalName>project</finalName>-1.0</finalName>
    <pluginManagement
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin/artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin/artifactId>
          <version>2.2-beta-2</version>
        </plugin>
        <plugin>
          <artifactId>maven-clean-plugin/artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin/artifactId>
          <version>2.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin/artifactId>
          <version>2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin/artifactId>
          <version>2.4</version>
        </plugin>
        <plugin>
          <artifactId>maven-ear-plugin/artifactId>
          <version>2.3.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-ejb-plugin/artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin/artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin/artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-javadoc-plugin/artifactId>
          <version>2.5</version>
        </plugin>
        <plugin>
          <artifactId>maven-plugin-plugin/artifactId>
          <version>2.4.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-rar-plugin/artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin/artifactId>
          <version>2.0-beta-8</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin/artifactId>
          <version>2.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin/artifactId>
          <version>2.0-beta-7</version>
        </plugin>
        <plugin>
          <artifactId>maven-source-plugin/artifactId>
          <version>2.0.4</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin/artifactId>
          <version>2.4.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin/artifactId>
          <version>2.1-alpha-2</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-help-plugin/artifactId>
        <version>2.1.1</version>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>/enabled>
      </snapshots>
      <id>central</id>/id>
      <name>Maven Repository Switchboard</name>/name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>/updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>/enabled>
      </snapshots>
      <id>central</id>/id>
      <name>Maven Plugin Repository</name>/name>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <reporting>
    <outputDirectory>C:\MVN\project\target/site</outputDirectory>
  </reporting>
</project>

In the above pom.xml, you can see the default project source code directory structure, output directory, required plugins, repositories, and report directories that Maven needs to use when executing targets.

Maven's pom.xml file does not need to be manually written.

Maven provides a large number of archetype plugins to create projects, including project structure and pom.xml.

POM Tag Comprehensive Explanation

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
    <!--The coordinates of the parent project. If no value is specified for an element in the project, the corresponding value in the parent project is the default value for the project. Coordinates include group ID, artifact ID and 
        version. -->
    <parent>
        <!--Artifact identifier of the inherited parent project -->
        <artifactId />
        <!--Global unique identifier of the inherited parent project -->
        <groupId />
        <!--Version of the inherited parent project -->
        <version />
        <!-- Relative path of the pom.xml file of the inherited parent project. The relative path allows you to choose a different path. The default value is ../pom.xml. Maven first looks for the parent project's pom.xml file in the location where the current project is being built 
            Purpose pom, first in this location in the file system (relativePath location), then in the local repository, and finally in the remote repository to find the parent project's pom. -->
        <relativePath />
    </parent>
    <!--Declare which POM model version the project descriptor follows. The version of the model itself changes little, although it is still indispensable, as it ensures stability when Maven introduces new features or other model changes. -->
    <modelVersion>4.0.0</modelVersion>/modelVersion>
    <!--Global unique identifier of the project, usually distinguished from other projects by the fully qualified package name. And the path generated during the build is also generated from this, such as the relative path generated from com.mycompany.app is:/com/mycompany/app -->
    <groupId>asia.banseon</groupId>/groupId>
    <!-- Identifier of the artifact, which, together with the group ID, uniquely identifies an artifact. In other words, you cannot have two different projects with the same artifact ID and group ID; in some 
        Artifact ID must also be unique under a specific group ID. An artifact is something produced or used by a project, Maven artifacts produced for a project include: JARs, source code, binary releases, and WARs, etc. -->
    <artifactId>banseon</artifactId>-maven2</artifactId>
    <!--Type of artifact generated by the project, such as jar, war, ear, pom. Plugins can create their own artifact types, so the list is not exhaustive of all artifact types -->
    <packaging>jar</packaging>/packaging>
    <!--Current version of the project, formatted as: main version.minor version.incremental version-Specified version number -->
    <version>1.0-SNAPSHOT</version>
    <!--Name of the project, used by Maven-generated documents -->
    <name>banseon-maven</name>
    <!--URL of the project homepage, used by Maven-generated documents -->
    <url>http://www.baidu.com/banseon</url>
    <!-- Detailed description of the project, used by Maven-generated documents. When this element can be described in HTML format (for example, text in CDATA is ignored by the parser, so HTML can be included 
        Sign), do not encourage the use of plain text descriptions. If you need to modify the index page of the generated web site, you should modify your own index page file instead of adjusting the document here. -->
    <description>A maven project to study maven.</description>
    <!--Describes the prerequisites in the project build environment. -->
    <prerequisites
        <!--The minimum version of Maven required to build this project or use this plugin -->
        <maven />
    </prerequisites>
    <!--The name and URL of the issue management system (Bugzilla, Jira, Scarab, or any issue management system you like) used by the project, this example is jira -->
    <issueManagement
        <!--The name of the issue management system (such as jira), -->
        <system>jira</system>
        <!--The URL of the issue management system used by this project -->
        <url>http://jira.baidu.com/banseon</url>
    </issueManagement>
    <!--Continuous integration information for the project -->
    <ciManagement
        <!--The name of the continuous integration system, for example, continuum -->
        <system />
        <!--The URL of the continuous integration system used by this project (if the continuous integration system has a web interface). -->
        <url />
        <!--Developers who need to be notified when the build is completed/User configuration options. Including notifier information and notification conditions (error, failure, success, warning) -->
        <notifiers
            <!--Configure a method to notify users when the build is interrupted/Developer -->
            <notifier
                <!--The method for delivering notifications -->
                <type />
                <!--Whether to notify when an error occurs -->
                <sendOnError />
                <!--Whether to notify when the build fails -->
                <sendOnFailure />
                <!--Whether to notify when the build is successful -->
                <sendOnSuccess />
                <!--Whether to notify when a warning occurs -->
                <sendOnWarning />
                <!--Not recommended for use. Where to send the notifications -->
                <address />
                <!--Extended configuration options -->
                <configuration />
            </notifier>
        </notifiers>
    </ciManagement>
    <!--The year the project was created,4A number. This value needs to be used when generating copyright information. -->
    <inceptionYear />
    <!--Information about the email lists related to the project -->
    <mailingLists>
        <!--This element describes all the email lists related to the project. The automatically generated website references this information. -->
        <mailingList>
            <!--The name of the email -->
            <name>Demo</name>
            <!--The address or link for sending emails, if it is an email address, the mailto: link will be automatically created when the document is created -->
            <post>[email protected]</post>
            <!--The address or link for the subscription email, if it is an email address, the mailto: link will be automatically created when the document is created -->
            <subscribe>[email protected]</subscribe>
            <!--Email address or link to unsubscribe from the mailing list, if it is an email address, a mailto: link will be automatically created when the document is created -->
            <unsubscribe>[email protected]</unsubscribe>
            <!--URL where you can browse email information -->
            <archive>http:/hi.baidu.com/banseon/demo/dev/</archive>
        </mailingList>
    </mailingLists>
    <!--List of project developers -->
    <developers
        <!--Information about a project developer -->
        <developer
            <!--Unique identifier of the project developer in the SCM -->
            <id>HELLO WORLD</id>
            <!--Full name of the project developer -->
            <name>banseon</name>
            <!--Email of the project developer -->
            <email>[email protected]</email>
            <!--URL of the homepage of the project developer -->
            <url />
            <!--The roles played by the project developers in the project, the role element describes various roles -->
            <roles
                <role>Project Manager</role>
                <role>Architect</role>
            </roles>
            <!--The organization to which the project developers belong -->
            <organization>demo</organization>
            <!--URL of the organization to which the project developers belong -->
            <organizationUrl>http://hi.baidu.com/banseon</organizationUrl>
            <!--Properties of the project developers, such as how instant messaging is handled, etc. -->
            <properties
                <dept>No</dept>
            </properties>
            <!--The timezone of the project developers, -11to12Integer within the range. -->
            <timezone-5</timezone>
        </developer>
    </developers>
    <!--List of other contributors of the project -->
    <contributors
        <!--Other contributors of the project. See developers/developer element -->
        <contributor
            <name />
            <email />
            <url />
            <organization />
            <organizationUrl />
            <roles />
            <timezone />
            <properties />
        </contributor>
    </contributors>
    <!--This element describes the list of all licenses for the project. It should only list the license list of the project, not the license list of dependent projects. If multiple licenses are listed, users can choose one of them instead of accepting all licenses. -->
    <licenses>
        <!--Describes the project license, used to generate the license page of the project web site, and is also used by some other reports and validations. -->
        <license>
            <!--The legal name of the license -->
            <name>Apache 2</name>
            <!--The URL of the official license text page -->
            <url>http://www.baidu.com/banseon/LICENSE-2.0.txt</url>
            <!--The main method of project distribution: repo, which can be downloaded from the Maven repository; manual, the user must manually download and install dependencies -->
            <distribution>repo</distribution>
            <!--Additional information about the license -->
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>
    <!--The SCM (Source Control Management) tag allows you to configure your code repository for use by Maven web sites and other plugins. -->
    <scm>
        <!--The URL of the SCM, which describes the version repository and how to connect to the repository. For details, please refer to the URL format and list provided by SCMs. This connection is read-only. -->
        <connection>
            scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk)
        </connection>
        <!--Used for developers, similar to the connection element. That is, this connection is not only read-only -->
        <developerConnection>
            scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk
        </developerConnection>
        <!--The current tag of the code, which is set to HEAD by default in the development stage -->
        <tag />
        <!--The URL that points to the browsable SCM repository for the project (e.g., ViewVC or Fisheye). -->
        <url>http://svn.baidu.com/banseon</url>
    </scm>
    <!--Describes various attributes of the organization to which the project belongs. The documents generated by Maven use -->
    <organization>
        <!--The full name of the organization -->
        <name>demo</name>
        <!--URL of the organization's homepage -->
        <url>http://www.baidu.com/banseon</url>
    </organization>
    <!--Information needed to build the project -->
    <build
        <!--This element sets the project source code directory. When building the project, the build system will compile the source code in the directory. This path is a relative path to pom.xml. -->
        <sourceDirectory />
        <!--This element sets the directory for the project script source code, which is different from the source code directory: in most cases, the contents of this directory will be copied to the output directory (because the script is interpreted, not compiled). -->