The interpretation of MAVEN project Pom.xml file

Source: Internet
Author: User

At the heart of Maven is the POM.XML,POM (Project object model), which defines the basic information of the project, which describes how to build and declare project dependencies. Take the Hello World project as an example, create a Hello-world folder with a new Pom.xml file that reads as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "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.autonavi</groupId><Artifactid>Roadtaskservice</Artifactid><Packaging>War</Packaging><version>1.0-snapshot</version><name>Roadtaskservice</name></Project>

The first line of code is the XML header, which specifies the version and encoding of the XML document. followed by the project element, project is the root element of all pom.xml, it also declares some pom-related namespaces and XSD elements, although these properties are not required, but using these properties allows third-party tools to help us quickly edit the POM. The most important part of this code is the three lines that contain Groupid,artifactid and version, which define the basic coordinates of a project, and in the world of Maven, any jar,pom or war is differentiated based on these basic coordinates.
GroupID defines which group the project belongs to, which is often associated with the organization or company where the project resides. For example, if a project called MyApp is built on Googlecode, then GroupID should be Com.googlecode.myapp,artifactid defines the unique ID of the current MAVEN project in the group, and we have this Hello The World Project defines Artifactid as Hello-world. Version specifies the current release--1.0-snapshot of the Hello World project. Snapshot is a snapshot, indicating that the project is still in development and is an unstable version.

If you need to reference a jar package, you need the dependencies element, which can contain multiple dependency elements to declare the dependencies of the project. For example, the following dependencies.

        <Dependencies>        <Dependency>            <groupId>Javax.validation</groupId>            <Artifactid>Validation-api</Artifactid>            <version>1.0.0.GA</version>            <Scope>Compile</Scope>        </Dependency>        </Dependencies>

In addition to the three essential elements of groupid,artifactid,version, there is a scope element that represents a dependency range, and if the dependency is test, that dependency is only valid for testing.

The interpretation of MAVEN project Pom.xml file

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.