maven pom.xml 详细
一、什么是POM
Project Object Model,项目对象模型。通过xml格式保存的pom.xml文件。作用类似ant的build.xml文件,功能更强大。该文件用于管理:源代码、配置文件、开发者的信息和角色、问题追踪系统、组织信息、项目授权、项目的url、项目的依赖关系等等。
一个完整的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/maven-v4_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>
 
二、基本设置
1、maven的协作相关属性
- <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/maven-v4_0_0.xsd">
 - <modelVersion>4.0.0</modelVersion>
 - <groupId>org.codehaus.mojo</groupId>
 - <artifactId>my-project</artifactId>
 - <version>1.0</version>
 - <packaging>war</packaging>
 - </project>
 
- groupId : 组织标识,例如:org.codehaus.mojo,在M2_REPO目录下,将是: org/codehaus/mojo目录。
 - artifactId : 项目名称,例如:my-project,在M2_REPO目录下,将是:org/codehaus/mojo/my-project目录。
 - version : 版本号,例如:1.0,在M2_REPO目录下,将是:org/codehaus/mojo/my-project/1.0目录。
 - packaging : 打包的格式,可以为:pom , jar , maven-plugin , ejb , war , ear , rar , par
 
2、POM之间的关系
主要用于POM文件的复用。
a)依赖关系:依赖关系列表(dependency list)是POM的重要部分
- <dependencies>
 - <dependency>
 - <groupId>junit</groupId>
 - <artifactId>junit</artifactId>
 - <version>4.0</version>
 - <scope>test</scope>
 - </dependency>
 - …
 - </dependencies>
 
- groupId , artifactId , version :
 - scope : compile(default),provided,runtime,test,system
 - exclusions
 
b)继承关系:继承其他pom.xml配置的机制。
比如父pom.xml:
- <project>
 - [...]
 - <dependencies>
 - <dependency>
 - <groupId>junit</groupId>
 - <artifactId>junit</artifactId>
 - <version>4.4</version>
 - <scope>test</scope>
 - </dependency>
 - </dependencies>
 - [...]
 - </project>
 
在子pom.xml文件继承它的依赖(还可以继承其他的:developers and contributors、plugin lists、reports lists、plugin executions with matching ids、plugin configuration):
- [...]
 - <parent>
 - <groupId>com.devzuz.mvnbook.proficio</groupId>
 - <artifactId>proficio</artifactId>
 - <version>1.0-SNAPSHOT</version>
 - </parent>
 - [...]
 
在这种机制下,maven还提供了一个类似java.lang.Object的顶级父pom.xml文件:
- <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>${project.artifactId}-${project.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>
 - <pluginManagement>
 - <plugins>
 - <plugin>
 - <artifactId>maven-antrun-plugin</artifactId>
 - <version>1.1</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.3</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.4</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-plugin-plugin</artifactId>
 - <version>2.4.1</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-rar-plugin</artifactId>
 - <version>2.2</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-release-plugin</artifactId>
 - <version>2.0-beta-7</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-resources-plugin</artifactId>
 - <version>2.2</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-site-plugin</artifactId>
 - <version>2.0-beta-6</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-source-plugin</artifactId>
 - <version>2.0.4</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-surefire-plugin</artifactId>
 - <version>2.4.2</version>
 - </plugin>
 - <plugin>
 - <artifactId>maven-war-plugin</artifactId>
 - <version>2.1-alpha-1</version>
 - </plugin>
 - </plugins>
 - </pluginManagement>
 - </build>
 - <reporting>
 - <outputDirectory>target/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.xml受到超pom.xml文件的影响:
mvn help:effective-pom
c)聚合关系:用于将多个maven项目聚合为一个大的项目。
- <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/maven-v4_0_0.xsd">
 - <modelVersion>4.0.0</modelVersion>
 - <groupId>org.codehaus.mojo</groupId>
 - <artifactId>my-parent</artifactId>
 - <version>2.0</version>
 - <modules>
 - <module>my-project<module>
 - </modules>
 - </project>
 
3、属性
maven的属性,是值的占位符,类似EL,类似ant的属性,比如${X},可用于pom文件任何赋值的位置。有以下分类:
- env.X:操作系统环境变量,比如${env.PATH}
 - project.x:pom文件中的属性,比如:<project><version>1.0</version></project>,引用方式:${project.version}
 - settings.x:settings.xml文件中的属性,比如:<settings><offline>false</offline></settings>,引用方式:${settings.offline}
 - Java System Properties:java.lang.System.getProperties()中的属性,比如java.home,引用方式:${java.home}
 - 自定义:在pom文件中可以:<properties><installDir>c:/apps/cargo-installs</installDir></properties>,引用方式:${installDir}
 
4、构建设置
构建有两种build标签:
- <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/maven-v4_0_0.xsd">
 - …
 - <!– "Project Build" contains more elements than just the BaseBuild set –>
 - <build>…</build>
 - <profiles>
 - <profile>
 - <!– "Profile Build" contains a subset of "Project Build"s elements –>
 - <build>…</build>
 - </profile>
 - </profiles>
 - </project>
 
build中的主要标签:Resources和Plugins。
Resources:用于排除或包含某些资源文件
- <resources>
 - <resource>
 - <targetPath>META-INF/plexus</targetPath>
 - <filtering>false</filtering>
 - <directory>${basedir}/src/main/plexus</directory>
 - <includes>
 - <include>configuration.xml</include>
 - </includes>
 - <excludes>
 - <exclude>**/*.properties</exclude>
 - </excludes>
 - </resource>
 - </resources>
 
Plugins:设置构建的插件
- <build>
 - …
 - <plugins>
 - <plugin>
 - <groupId>org.apache.maven.plugins</groupId>
 - <artifactId>maven-jar-plugin</artifactId>
 - <version>2.0</version>
 - <extensions>false</extensions>
 - <inherited>true</inherited>
 - <configuration>
 - <classifier>test</classifier>
 - </configuration>
 - <dependencies>…</dependencies>
 - <executions>…</executions>
 - </plugin>
 
maven pom.xml 详细的更多相关文章
- maven  pom.xml详细介绍,必须留一份
		
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
 - 史上最全的maven pom.xml文件教程详解
		
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
 - (转)Maven pom.xml 配置详解
		
背景:maven一直感觉既熟悉又陌生,归根结底还是自己不太熟. 1 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者 ...
 - Maven(四-2) Maven pom.xml 配置详解
		
转载于:http://niuzhenxin.iteye.com/blog/2042102 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述 ...
 - Maven pom.xml 全配置(一)常用配置
		
Maven pom.xml 全配置(一)常用配置 这里贴出一个Maven中出现频率较高的配置参数注释,方便理解项目中Maven的配置具体的作用.如果在此博文中没有找到你想看到的参数,可以移步Maven ...
 - Maven - pom.xml 文件
		
章节 Maven – 简介 Maven – 工作原理 Maven – Repository(存储库) Maven – pom.xml 文件 Maven – 依赖管理 Maven – 构建生命周期.阶段 ...
 - myeclipse maven pom.xml 配置错误
		
http://www.oschina.net/question/2265006_219341#tags_nav maven pom.xml 配置文件错误 腾讯云消息队列CMQ架构解析> ...
 - 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样
		
[参考]:maven pom.xml加载不同properties配置[转] 首先 看看效果: 点开我们项目中的Maven projects 后,会发现右侧 我们profile有个可勾选选项.默认勾选l ...
 - Maven pom.xml文件详解
		
Maven pom.xml文件详解 一.简介 POM全称是Project Object Model,即项目对象模型. pom.xml是maven的项目描述文件,它类似与antx的project.xml ...
 
随机推荐
- esp8266 SDK开发之GPIO中断
			
先秀一下自己焊的板子,黑的开关用于复位,蓝的开关用于烧录程序. 首先要明确的是esp8622的大多数管脚都有多个功能, 比如可以用来当做GPIO管脚,还可以用来当做SPI管脚. 如下图所示 使用PIN ...
 - 01-java技术体系基础
			
java体系基础 理论 编程语言: 系统级: C, C++, go, erlang ... 应用级: C#, Java, Python, Perl, Ruby, php 虚拟机: jvm(java虚拟 ...
 - Git添加远程库和从远程库中获取
			
一. Git添加远程库 1. 在本地新建一个文件夹,在该文件夹使用Git工具,运行$ git init,将该文件夹变为本地Git仓库,同时会生成一个隐藏的.git文件夹. 2. 在该文件夹中用Note ...
 - SQLServer Agent执行[分发清除: distribution] 无法删除快照文件
			
由于之前创建的发布订阅造成严重的性能压力,症状表现为发布订阅表查询产生CMEMTHREAD suspend等待,由于开发配置每隔十分钟会产生大量的SQLCOMMAND(create table,cr ...
 - swiper轮播问题之一:轮播图内容为动态数据生成时轮播图无法自动轮播
			
本人在用H5做移动端项目中使用Swiper遇到的两个问题,因此加深了对Swiper的掌握,分享出来对刚开始接触Swiper的童鞋们或多或少会有帮助. 首先,new Swiper的初始化最 ...
 - H5 + 开发App(分享功能)
			
我们开发App有一个不可少的功能,就是分享功能.让用户将app分享到他的社交圈.比如微信 QQ 微博等等. 准备工作:我们要先去申请相关的权限, 这是传送门http://ask.dcloud.net. ...
 - File API文件操作之FileReader
			
近来研究点对点的文件传输,想到一种方案FileReader+WebRtc. 当我看到FileReader的时候,哎呀,不错的东西啊,仔细一看属于File API,或者叫做Web API. File A ...
 - Ajax的请求方式几传参的区别
			
Get,Post,Put,Delete请求(ajax)方式的不通. http://blog.jobbole.com/99854/
 - Jerry的CDS view自学系列
			
My CDS view self study tutorial - part 1 how to test odata service generated by CDS view https://blo ...
 - Zabbix实战-简易教程--技巧一(操作类技巧)
			
一.常用操作技巧 1.克隆 监控项.模板.触发器都可以进行克隆.其中,模板克隆又分为克隆和完全克隆.完全克隆会将LLD也一起复制一份,就是和之前的模板一模一样,而模板的克隆只是克隆监控项,不复制低层次 ...