以下引用自官方的POM介绍https://maven.apache.org/guides/introduction/introduction-to-the-pom.html

一、什么是POM?

项目对象模型或POM是Maven的基本工作单元。它是一个XML文件,其中包含有关Maven用于构建项目的项目和配置详细信息。它包含大多数项目的默认值。示例是构建目录,即target;这是源目录src/main/java;测试源目录src/test/java;等等。

POM已从Maven 1中的project.xml重命名为Maven 2中的pom.xml。而不是具有包含可执行目标的maven.xml文件,目标或插件现在已在pom.xml中配置。执行任务或目标时,Maven会在当前目录中查找POM。它读取POM,获取所需的配置信息,然后执行目标。

可以在POM中指定的一些配置是项目依赖性,可执行的插件或目标,构建配置文件等。还可以指定其他信息,如项目版本,描述,开发人员,邮件列表等。

二、超级POM

超级POM是Maven的默认POM。所有POM扩展超级POM,除非明确设置,这意味着超级POM中指定的配置由您为项目创建的POM继承。下面的代码片段是Maven 2.0.x的超级POM。

 <project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name> <repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> <pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories> <build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${artifactId}-${version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build> <reporting>
<outputDirectory>target/site</outputDirectory>
</reporting> <profiles>
<profile>
<id>release-profile</id> <activation>
<property>
<name>performRelease</name>
</property>
</activation> <build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId> <configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles> </project>

下面的代码片段是Maven 2.1.x的超级POM。

 <project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name> <repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> <pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories> <build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<!-- TODO: MNG-3731 maven-plugin-tools-api < 2.4.4 expect this to be relative... -->
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<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-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</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>maven-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>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0-beta-7</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
</plugin>
</plugins>
</pluginManagement>
</build> <reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting>
<profiles>
<profile>
<id>release-profile</id> <activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation> <build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles> </project>

三、最小的POM要求

POM的最低要求如下:

  • project root - 项目根
  • modelVersion - 应设置为4.0.0
  • groupId - 项目组的ID。(理解为包名)
  • artifactId - 工件的ID(项目)
  • version - 指定组下的工件的版本

以下是一个例子:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>

POM要求配置其groupIdartifactIdversion。这三个值形成项目的完全合格的工件名称。这是以<groupId>:<artifactId>:<version>的形式。对于上面的示例,其完全限定的工件名称为“com.mycompany.app:my-app:1”。

此外,如上所提到的什么是POM,如果没有指定的配置细节,Maven将使用默认值。这些默认值之一是打包类型。每个Maven项目都有一个打包类型。如果在POM中没有指定,那么将使用默认值“jar”。

此外,你可以看到,在最小POM,在库中未指定。如果您使用最小POM构建项目,它将继承超级POM中的存储库配置。因此,当看到Maven的在最小POM的依赖关系,它会知道这些依赖关系将在这里http://repo.maven.apache.org/maven2这是在超级POM中指定)被下载。

总结:

1、pom.xml文件是Maven构建的基础,而一个标准的pom.xml文件中,最基本是由groupId、artifactId、version这三个字段组成;在创建pom.xml之后,必须确定这三个属性,因为这三个属性在项目仓库是作为唯一标识的。

2、而对于三个属性的基本理解如下:

groupId:命名空间,比如com.jsoft.test

artivactId:项目名称,比如testproject

version:版本号,比如1.0

3、以下为标准的pom.xml包含的字段:

<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> <!-- The Basics -->
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>...</packaging>
<dependencies>...</dependencies>
<parent>...</parent>
<dependencyManagement>...</dependencyManagement>
<modules>...</modules>
<properties>...</properties> <!-- Build Settings -->
<build>...</build>
<reporting>...</reporting> <!-- More Project Information -->
<name>...</name>
<description>...</description>
<url>...</url>
<inceptionYear>...</inceptionYear>
<licenses>...</licenses>
<organization>...</organization>
<developers>...</developers>
<contributors>...</contributors> <!-- Environment Settings -->
<issueManagement>...</issueManagement>
<ciManagement>...</ciManagement>
<mailingLists>...</mailingLists>
<scm>...</scm>
<prerequisites>...</prerequisites>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<distributionManagement>...</distributionManagement>
<profiles>...</profiles>
</project>

提示:更详细的说明,参考官方解释:http://maven.apache.org/pom.html

4、还有一个重要的点,一般项目分模块进行开发,那么在pom.xml中也有体现,比如一个总的pom.xml管理这每一个模块的pom.xml,这种做法叫做分模块。

以上参考:http://www.yiibai.com/maven/maven_pom.html

Maven的POM简单理解的更多相关文章

  1. maven命令的简单理解

    mvn clean //在target文件夹中的一切都将被删除 mvn compile //编译源代码 mvn test  //运行应用程序中的单元测试 mvn package  //把jar打到本项 ...

  2. Maven项目pom.xml文件简单解析

    Maven项目pom.xml简单解析 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="h ...

  3. (六)Maven之pom.xml文件简单说明

    通过前面几部分知识,我们对maven已经有了初步的印象,就像Make的Makefile.Ant的build.xml一样,Maven项目的核心是pom.xml.POM(Project Object Mo ...

  4. maven的pom.xml深入理解

    maven的pom.xml的具体使用和各个xml标签的作用.这样设计的原理是什么? maven实战的第17章-18章是架构方面的知识

  5. Maven的pom文件内容详细理解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  6. Maven 教程(6)— Maven之pom.xml文件简单说明

    原文地址:https://blog.csdn.net/liupeifeng3514/article/details/79543963 通过前面几部分知识,我们对maven已经有了初步的印象,就像Mak ...

  7. 淘淘商城基于maven和svn的理解

    首先了解下maven和svn是什么: Maven是一个项目的管理工具,它包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目的生命周期(Project Life ...

  8. Maven就是这么简单

    什么是Maven Maven是一个采用纯Java编写的开源项目管理工具, Maven采用了一种被称之为Project Object Model (POM)概念来管理项目,所有的项目配置信息都被定义在一 ...

  9. Maven的pom.xml配置文件详解

    Maven简述 Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具.由于 Mav ...

随机推荐

  1. 字符串-POJ3974-Palindrome

    Palindrome Time Limit: 15000MS Memory Limit: 65536K Description Andy the smart computer science stud ...

  2. VSCode编译C/C++(一)MinGW安装配置指南

    为什么不用IDE? 更加专业.轻便.其过程对于理解计算机也有更多的帮助 安装过程: 首先进入http://mingw.org/  ,点击右侧最新发布,可以下载,然后安装 点击桌面MinGWInstal ...

  3. ubuntu12.04 ppa安装git

    PPA地址:https://launchpad.net/~git-core/+archive/ppa 支持所有的Ubuntu版本. 运行命令: sudo apt-add-repository ppa: ...

  4. Root CA certificate:ApacheJMeterTemporaryRootCA.crt created in JMeter bin directory

    今天学习jmeter录制,在点击start之后弹出: 且在jmeter安装目录里确实生成了ApacheJMeterTemporaryRootCA.crt文件 上网查询官方文档http://120.52 ...

  5. window 7上安装Visual Studio 2017失败的解决方法

    今天在办公电脑上windows 7系统上装Visual Studio 2017企业版的时候遇到了一个让人懵逼的错误. 为啥说懵逼呢,因为昨天楼主在台式机上同样安装2017没有任何问题啊,台式机上是wi ...

  6. 在ie9下在textbox框里面输入内容按enter键会触发按钮的事件

    问题 在ie下,如果存在有button标签,如果在textbox里面输入内容,按下enter键,则会触发第一个按钮的click事件,经过测试,在IE10以及以下的都存在这个问题 原因 浏览器默认行为不 ...

  7. xml编辑无提示?这么破!

    在学习testng这个单元测试框架时,如果咱们碰到了编辑测试套件xml,不提示的情况(有提示方便咱们学习,并且testng的测试套件定义必须按照他的dtd文件约束来),咱们可以按照下面的步骤去解决这个 ...

  8. Python-函数参数的传递

    作者:Vamei 出处:http://www.cnblogs.com/vamei,感谢博主的分享, python的函数参数传递有这样的几种形式: 1.位置传递 2.关键字传递 3.参数默认值传递 4. ...

  9. [办公软件篇][2]source-insight安装

    http://jingyan.baidu.com/article/a3f121e4fe173ffc9052bbb0.html 注意看:同步代码

  10. 在SAE搭建微信公众账号服务

    让我们回到2014年11月,从公司请假回成都,在天府软件园B区旁边的小区里,那个10多平米的出租屋里,闲来无事,我想找个事情做一做,好让我这漂浮的心静下来.大约在半年前就申请了微信的一个公众账号,一直 ...