POM (Project Object Model, Project object Model) is the basic unit of work of the Maven project. It is a XML file that contains basic information about the project, which describes how the project is built, declares project dependencies, and so on.
When performing a task or target, Maven looks for POM in the current directory. It reads the POM, gets the required configuration information, and then executes the target.
The following configurations can be specified in POM:
Project dependence
Plug-in
Executive goal
Project build profile
Project version
List of project developers
Related mailing list information
Before creating a POM, we first need to describe the project team (groupId), the unique ID of the project.
4.0.0 com.companyname.project-group project 1.0 All POM files require the project element and three required fields: groupId,artifactId,version.
Node
Description
Project
The root label of the project.
ModelVersion
The model version needs to be set to 4.0.
GroupId
This is the logo of the engineering team. It is usually unique in an organization or project. For example, a banking organization, com.companyname.project-group, owns all the bank-related projects.
ArtifactId
This is the logo of the project. It is usually the name of the project. For example, consumer banks. GroupId and artifactId together define the location of artifact in the warehouse.
Version
This is the version number of the project. In the artifact repository, it is used to distinguish between different versions. For example:
com.company.bank:consumer-banking:1.0 com.company.bank:consumer-banking:1.1
11.3.1. Parent (Super) POM ¶
Parent (Super) POM is the default POM for Maven. All POM inherits from a parent POM (whether or not the parent POM is explicitly defined). The parent POM contains some default settings that can be inherited. Therefore, when Maven finds that it needs to download a dependency in POM, it goes to the default repository http://repo1.maven.org/maven2 configured in Super POM to download it.
Maven uses effective pom (Super pom plus the project’s own configuration) to implement related goals, which helps developers make as few configurations as possible in pom.xml, which can of course be rewritten.
Use the following command to view the Super POM default configuration:
mvn help:effective-pom
Next, we create the directory MVN/project, and create a pom.xml under that directory, as follows:
4.0.0 com.companyname.project-group project 1.0 In the command console, go to the MVN/project directory and 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 results of Effective POM, as shown in the console, are inherited and interpolated to make the configuration take effect.
4.0.0 com.companyname.project-group project 1.0 C:\MVN\project\src\main\java src/main/scripts C:\MVN\project\src\test\java C:\MVN\project\target\classes C:\MVN\project\target\test-classes resource-0 C:\MVN\project\src\main\resources resource-1 C:\MVN\project\src\test\resources C:\MVN\project\target project-1.0 maven-antrun-plugin 1.3 maven-assembly-plugin 2.2-beta-2 maven-clean-plugin 2.2 maven-compiler-plugin 2.0.2 maven-dependency-plugin 2.0 maven-deploy-plugin 2.4 maven-ear-plugin 2.3.1 maven-ejb-plugin 2.1 maven-install-plugin 2.2 maven-jar-plugin 2.2 maven-javadoc-plugin 2.5 maven-plugin-plugin 2.4.3 maven-rar-plugin 2.2 maven-release-plugin 2.0-beta-8 maven-resources-plugin 2.3 maven-site-plugin 2.0-beta-7 maven-source-plugin 2.0.4 maven-surefire-plugin 2.4.3 maven-war-plugin 2.1-alpha-2 maven-help-plugin 2.1.1 false central Maven Repository Switchboard http://repo1.maven.org/maven2 never false central Maven Plugin Repository http://repo1.maven.org/maven2 C:\MVN\project\target/site In the above pom.xml, you can see the default project source directory structure, output directory, required plug-ins, warehouse and report directory that Maven needs to use to execute the target.
The pom.xml file for Maven also does not need to be written by hand.
Maven provides a large number of prototype plug-ins to create projects, including engineering structures and pom.xml.
11.3.2. A detailed explanation of POM tags ¶
4.0.0 asia.banseon banseon-maven2 jar 1.0-SNAPSHOT banseon-maven http://www.baidu.com/banseon A maven project to study maven. jira http://jira.baidu.com/banseon Demo banseon@126.com banseon@126.com banseon@126.com http:/hi.baidu.com/banseon/demo/dev/ HELLO WORLD banseon banseon@126.com Project Manager Architect demo http://hi.baidu.com/banseon No -5 Apache 2 http://www.baidu.com/banseon/LICENSE-2.0.txt repo A business-friendly OSS license scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk) scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk http://svn.baidu.com/banseon demo http://www.baidu.com/banseon ...... ...... Windows XP Windows x86 5.1.2600 mavenVersion 2.0.3 /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ ...... ...... ...... ...... ...... ...... banseon-repository-proxy banseon-repository-proxy http://192.168.1.169:9999/repository/ default ...... org.apache.maven maven-artifact 3.8.1 jar test spring-core org.springframework true ...... banseon-maven2 banseon maven2 file://${basedir}/target/deploy banseon-maven2 Banseon-maven2 Snapshot Repository scp://svn.baidu.com/banseon:/usr/local/maven-snapshot banseon-site business api website scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web