您的位置:首页 > 其它

Maven的配置文件pom.xml

2017-08-15 11:21 405 查看
http://www.cnblogs.com/yakov/archive/2011/11/26/maven_pom.html 原址

简介:

什么是POM?

POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml。在Maven中,当谈到Project的时候,不仅仅是一堆包含代码的文件。一个Project往往包含一个配置文件,包括了与开发者有关的,缺陷跟踪系统,组织与许可,项目的URL,项目依赖,以及其他。它包含了所有与这个项目相关的东西。事实上,在Maven世界中,project可以什么都没有,甚至没有代码,但是必须包含pom.xml文件。

概览

下面是一个POM项目中的pom.xml文件中包含的元素。注意,其中的modelVersion是4.0.0,这是当前仅有的可以被Maven2&3同时支持的POM版本,它是必须的。

1 <project xmlns="http://maven.apache.org/POM/4.0.0"
2          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4             http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5     <modelVersion>4.0.0</modelVersion>
6
7     <!-- 基本设置 -->
8     <groupId>...</groupId>
9     <artifactId>...</artifactId>
10     <version>...</version>
11     <packaging>...</packaging>
12     <dependencies>...</dependencies>
13     <parent>...</parent>
14     <dependencyManagement>...</dependencyManagement>
15     <modules>...</modules>
16     <properties>...</properties>
17
18     <!-- 构建过程的设置 -->
19     <build>...</build>
20     <reporting>...</reporting>
21
22     <!-- 项目信息设置 -->
23     <name>...</name>
24     <description>...</description>
25     <url>...</url>
26     <inceptionYear>...</inceptionYear>
27     <licenses>...</licenses>
28     <organization>...</organization>
29     <developers>...</developers>
30     <contributors>...</contributors>
31
32     <!-- 环境设置 -->
33     <issueManagement>...</issueManagement>
34     <ciManagement>...</ciManagement>
35     <mailingLists>...</mailingLists>
36     <scm>...</scm>
37     <prerequisites>...</prerequisites>
38     <repositories>...</repositories>
39     <pluginRepositories>...</pluginRepositories>
40     <distributionManagement>...</distributionManagement>
41     <profiles>...</profiles>
42 </project>


基本的设置:

POM包含了一个project所需要的所有信息,当然也就包含了构建过程中所需要的插件的配置信息,事实上,这里申明了"who","what",和"where",然而构建生命周期(build lifecycle)s中说的是"when"和"how"。这并不是说POM并能影响生命周期的过程-事实上它可以。例如,配置一个可以嵌入ant任务到POM的mavem-antrun-plugin。它基本上就是一个声明。就像build.xml告诉ant当运行时它该做什么一样,一个POM申明了它自己的配置。如果外力迫使生命周期跳过了ant插件的执行,这并不影响那些已经执行过的插件产生的效果。这一点和build.xml不一样。

 

1 <project xmlns="http://maven.apache.org/POM/4.0.0"
2          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4             http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5     <modelVersion>4.0.0</modelVersion>
6     <groupId>org.codehaus.mojo</groupId>
7     <artifactId>my-project</artifactId>
8     <version>1.0</version>
9 </project>


Maven坐标

上面的POM定义的是Maven2&3都承认的最小部分。groupId:artifactId:version是必须的字段(尽管在继承中groupId和version不需要明确指出)。这三个字段就像地址和邮戳,它标记了仓库中的特定位置,就像Maven projects的坐标系统一样。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven