Ii. Explanation of pom. xml elements in Maven, mavenpom. xml

Source: Internet
Author: User

Ii. Explanation of pom. xml elements in Maven, mavenpom. xml

Reprinted please indicate the original address: http://www.cnblogs.com/ygj0930/p/6628201.html

A pom. xml file contains many tags. Each tag is a configuration for project lifecycle and dependency management. Common causes include:

1: <peoject>: root tag of pom. xml. A maven project is wrapped with a pair of <peoject> </project> labels.

2: <modelVersion>: maven version

3: coordinates of the current project and packaging method:

<GroupId>: corporate website anti-write + project name

<ArtifactId>: Project name-Module name

<Version>: version Number + Type

The version number is represented by three integers. Each integer is separated by ".", indicating a major version number, a branch version number, and a minor version number.

Type: Version type. Major versions: snapshot version (simplified version), alpha beta version, beta version, release stable version, and GA official release

<Packaging>: The packaging type. The default value is jar. It can be set to war, zip, or pom.

4: <name>: Current Project name

5: <url>: Project address

6: <description>: Project description

7: <developers>: developer information

8: <licenses>: Project license information, used to authorize others to use the project at the time of publication

9: <organization>: organization information, enterprise information

All the preceding configurations are related to this maven project.

10: <properties>: property value tag, also called variable tag. Like the property in Ant, you can use this label to include some attributes and specify the attribute value. In other parts of pom. xml, you can use the EL expression to access the variable method -- $ {attribute name} to obtain the specific attribute value. This is generally used as the content or global variables that need to be reused in the entire pom. xml file.

11: dependency labels

<Dependencies> <! -- A dependency package --> <dependency> <! -- Specify the dependent package through coordinates --> <groupId> </groupId> <artifactId> </artifactId> <version> </version> <! -- Optional: Scope of dependency. There are six optional values: Commonly Used compile/provided/test/runtime --> <scope> A range </scope> <! -- Optional: exclude dependency transfer: when the current project depends on the currently configured dependency Package A, if the dependent package is dependent on other packages B, you can exclude the dependency transfer here, do not download and import B --> <exclusions> <exclusion>
<! -- Excluded dependent package coordinates --> <groupId> </groupId> <artifactId> </artifactId> <version> </version>
            </exclusion>         </exclusions>    </dependency></dependencies>

 

12: dependency management label: it is mainly used to define the parent pom. xml. Other projects can inherit this pom. xml to avoid repeated definitions of some depency.

<DepencyManagement> <depencies> <depency> dependent package coordinates... </depency> </depencies> </depencyManagement>

13: <build>: Project Support labels, which are generally used to introduce plug-ins.

<Build> <plugins> <plugin> <! -- Plug-in coordinates --> <groupId> </groupId> <artifactId> </artifactId> <version> </version> other settings... </plugin> </plugins> </build>

14: <parent>: inherits tags from the parent project.

15: <moudules>: Aggregation tag, used to aggregate multiple maven projects. In this way, executing the pom with a command will execute all the aggregated projects and process multiple projects at the same time.

 

Example: A simple Java Web project pom. xml is 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/maven-v4_0_0.xsd"> <modelVersion> 4.0.0 </modelVersion> <groupId> com. test </groupId> <artifactId> WebApp </artifactId> <packaging> war </packaging> <version> 1.0 </version> <name> WebApp Maven Webapp </name> <url> http://maven.apa Che.org </url> <dependencies> <dependency> <groupId> commons-fileupload </groupId> <artifactId> commons-fileupload </artifactId> <version> 1.2.1 </version> </dependency> <! -- Commons-io: Optional dependency package for commons-fileupload --> <dependency> <groupId> commons-io </groupId> <artifactId> commons-io </artifactId> <version> 1.3.2 </version> </dependency> </dependencies> <build> <finalName> WebApp </finalName> </build> </project>

 

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.