MAVEN Learning---POM mechanism

Source: Internet
Author: User

The POM represents the engineering object model. It is the basic build when working with Maven and is an XML file. It is placed under the project root directory and the file is named Pom.xml.

The POM contains information about the engineering and various configuration details that Maven uses to build the project.

The POM also contains targets and plugins. When a task or target is executed, Maven looks for the POM under the current directory, reads the required configuration information from it, and then executes the target. Some of the configurations that can be set in the POM are as follows:

    • Project Dependencies
    • Plugins
    • Goals
    • Build profiles
    • Project version
    • Developers
    • Mailing list

Before we create the POM, we first determine the engineering group (GROUPID), its name (Artifactid), and its version, which are the unique identification of the project in the warehouse.

POM Example
<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">   <modelVersion>4.0.0</modelVersion>   <groupId>com.companyname.project-group</groupId>   <artifactId>project</artifactId>   <version>1.0</version></project>

It should be stated that each project should have only one POM file.

    • All POM files require a project element and three required fields: GroupId, artifactid,version.
    • The engineering identification in the warehouse is GroupId:artifactId:version
    • The root element of Pom.xml is project, which has three primary child nodes:
node Description
GroupId This is the identification of the engineering group. It is usually unique within an organization or project. For example, a bank organization Com.company.bank owns all the bank-related projects.
Artifactid This is the identification of the project. It is usually the name of the project. For example, consumer banks. Together, GroupId and Artifactid define the location of the artifact in the warehouse.
Version This is the version number of the project. In the artifact repository, it is used to differentiate between different versions. For example:
com.company.bank:consumer-banking:1.0
com.company.bank:consumer-banking:1.1.
Super POM

All Pom is inherited from a parent pom (whether or not the parent POM is explicitly defined). The parent Pom is also known as Super Pom, which contains some default settings that can be inherited.

Maven uses effective pom (Super Pom Plus Engineering's own configuration) to perform related goals, which help developers do as few configurations as possible in Pom.xml, and these configurations can be easily rewritten.

An easy way to view the Super POM default configuration is to execute the following command: MVN help:effective-pom

Create a Pom.xml file in any directory on your computer, using the content from the sample Pom mentioned above.

In the following example, we C:\MVN\project created a pom.xml file in the directory.

Now open the command console and execute the following MVN command in the directory where Pom.xml is located.

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

Maven will begin processing and displaying the effective-pom.

[INFO] Scanning for projects...[INFO] Searching repository for plugin with prefix: ‘help‘.[INFO] ------------------------------------------------------------------------[INFO] Building Unnamed - com.companyname.project-group:project-name:jar:1.0[INFO]    task-segment: [help:effective-pom] (aggregator-style)[INFO] ------------------------------------------------------------------------[INFO] [help:effective-pom {execution: default-cli}][INFO].....[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESSFUL[INFO] ------------------------------------------------------------------------[INFO] Total time: < 1 second[INFO] Finished at: Thu Jul 05 11:41:51 IST 2012[INFO] Final Memory: 6M/15M[INFO] ------------------------------------------------------------------------

Effective POM results as shown in the console, after inheritance, 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 Pro              ject--><!--' 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 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</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>r Esource-0</mergeid> <directory>c:\mvn\project\src\main\resources</directory> </resource> </resources> <testResources> <testResource> <mergeid >resource-1</mergeId> <directory>C:\MVN\project\src\test\resources</directory> </testr esource> </testResources> <directory>C:\MVN\project\target</directory> <finalname>proj ect-1.0</finalname> <pluginManagement> <plugins> <plugin> &LT;ARTIFACTID&G t;maven-antrun-plugin</artifactid> <version>1.3</version> </plugin> <plu Gin> <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-compile r-plugin</artifactid&Gt <version>2.0.2</version> </plugin> <plugin> <artifactid>maven-depende          ncy-plugin</artifactid> <version>2.0</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.4</version> </plu gin> <plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.3.1 </version> </plugin> <plugin> &LT;ARTIFACTID&GT;MAVEN-EJB-PLUGIN&LT;/ARTIFACTID&G          T <version>2.1</version> </plugin> <plugin> <artifactid>maven-install-p          lugin</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>mav          en-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> &lt ;version>2.3</version> </plugin> <plugin> <artifactid>maven-site-plugin&          lt;/artifactid> <version>2.0-beta-7</version> </plugin> <plugin> <artifactid>maven-source-plugin</artifactid> <version>2.0.4</version> </plugin> <plugin&          Gt <artifactId>maven-surefire-plugin</artifactId> <version>2.4.3</version> </plugi n> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-alp ha-2</version> </plugin> </plugins> </pluginManagement> <plugins> &lt      ;p lugin> <artifactId>maven-help-plugin</artifactId> <version>2.1.1</version>        </plugin> </plugins> </build> <repositories> <repository> <snapshots>  <enabled>false</enabled> </snapshots> <id>central</id> <name>maven Repository switchboard</name> <url>http://repo1.maven.org/maven2</url> </repository> &lt ;/repositories> <pluginRepositories> <pluginRepository> <releases> <updatePolicy>never< /updatepolicy> </releases> <snapshots> <enabled>false</enabled> </snap shots> <id>central</id> <name>maven Plugin repository</name> <url>http://r epo1.maven.org/maven2</url> </pluginRepository> </pluginRepositories> <reporting> &LT;OUTP Utdirectory>c:\mvn\project\target/site</outputdirectory> </reporting></project>

In the pom.xml above, you can see the default engineering source directory structure, output directory, required plug-ins, warehouses, and report directories that Maven needs to use when executing the target.

Maven's pom.xml files do not need to be written manually.

Maven provides a number of prototype plugins to create projects, including engineering structures and Pom.xml.

MAVEN Learning---POM mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.