Writing Pom.xml
This configuration file defines the basic information of the project, describes how the project was built, the dependencies of the project, and so on.
Example: The POM of Hello World
<span style="Font-size:small;"><?xml version="1.0"encoding="UTF-8"? ><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 "><modelVersion>4.0.0</modelversion><groupid>com.juvenxu.mvnbook</groupid><artifactid>hello-world</ Artifactid><version>1.0-snapshot</version><name>maven Hello World project</name></project></span>
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 enables third-party tools such as the XML editor in the IDE to help us quickly edit the POM.
The first child element under the root element, Modelversion, specifies the version of the current POM model, which can only be 4.0.0 for Maven2 and maven 3.
The most important part of this code is Groupid,artifactid and version three lines. These three elements define the basic coordinates of a project, and in Maven's world, 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 is located, such as when you set up a project called MyApp on Googlecode. Then GroupID should be Com.googlecode.myapp, if your company is mycom, there is a project for MyApp, then GroupID should be com.mycom.myapp. All the code in this book is based on GroupID Com.juvenxu.mvnbook.
Artifactid defines the unique ID of the current MAVEN project in the group, and we define Artifactid as Hello-world for this Hello World project, and other chapters of the book will be assigned other artifactid. In the previous example of GroupID for Com.googlecode.myapp, you might assign Artifactid to different sub-projects (modules), such as Myapp-util, Myapp-domain, Myapp-web, and so on.
As the name implies, 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. As the project progresses, version is constantly updated, such as upgrading to 1.0, 1.1-snapshot, 1.1, 2.0, and so on. Section 6.5 of this book describes snapshot in detail, and the 13th chapter describes how to use MAVEN to manage the upgrade release of a project version.
The last name element declares a more user-friendly project name, although this is not required, but I recommend declaring name for each POM to facilitate information exchange.
Without any actual Java code, we were able to define a maven project's Pom, which represents one of Maven's great strengths, which allows the project object model to be maximized to be independent of the actual code, which we can call decoupling, or orthogonality, This avoids the interaction between Java code and POM code to a large extent. For example, when the project needs to upgrade the version, only need to modify the POM, without the need to change the Java code, and after the Pom stable, the daily Java code development work basically does not involve the modification of POM.
Getting Started with Maven