这里详细讲解一下maven的pom文件
其中modelVersion包含4.0.0。这是目前唯一支持Maven 2和3的POM版本,并且始终是必需的。
pom标签列表
<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>
<! - 基础知识 - >
<groupId> ... </ groupId>
<artifactId> ... </ artifactId>
<version> ... </ version>
<packaging> ...... </ packaging>
<dependencies> ... </ dependencies>
<parent> ... </ parent>
<dependencyManagement> ... </ dependencyManagement>
<modules> ... </ modules>
<properties> ... </ properties>
<! - 构建设置 - >
<build> ... </ build>
<reporting> ... </ reporting>
<! - 更多项目信息 - >
<name> ... </ name>
<description> ... </ description>
<url> ... </ url>
<inceptionYear> ... </ inceptionYear>
<licenses> ... </ licenses>
<organization> ... </ organization>
<developers> ... </ developers>
<contributors> ... </ contributors>
<! - 环境设置 - >
<issueManagement> ... </ issueManagement>
<ciManagement> ... </ ciManagement>
<mailingLists> ... </ mailingLists>
<scm> ... </ scm>
<prerequisites> ... </prerequisites>
<repositories> ... </ repositories>
<pluginRepositories> ... </ pluginRepositories>
<distributionManagement> ... </ distributionManagement>
<profiles> ... </ profiles>
</项目>
重点讲解几个标签
properties、profiles、repositories、pluginRepositories、build
以上几个比较常用
<dependency>中会有classifier属性,标记使用版本或者运行环境(JDK5),type属性表示依赖扩展名,默认是jar
properties使用:
Maven属性是值占位符,通过使用符号$ {X},可以在POM内的任何位置访问它们的值,其中X是属性。或者插件可以将它们用作默认值
其实就是pom中的常量,可以在pom中被使用
它们有五种不同的风格:
env.X:
使用“env.”对变量进行前缀。将返回shell的环境变量。例如,$ {env.PATH}包含
PATH环境变量。
注意:虽然环境变量本身在Windows上不区分大小写,但属性的查找区分大小写。
换句话说,当Windows shell为%PATH%和%Path%返回相同的值时,
Maven会区分$ {env.PATH}和$ {env.Path}。从Maven 2.1.0开始,
为了可靠性,环境变量的名称被归一化为所有大写。
project.x:
POM中的点(.)标记路径将包含相应元素的值。例如:
<project>
<version> 1.0 </ version>
</project>
可通过$ {project.version}访问。
settings.x:
maven路径的settings.xml将包含相应的元素的值。例如:
<settings>
<offline> false </ offline>
</settings>
可通过$ {settings.offline}访问。
Java系统属性:
可通过java.lang.System.getProperties()访问的所有属性都可用作
POM属性,例如$ {java.home}。
x:在POM中的<properties />元素内设置。
<properties>
<someVar>value</someVar>
</properties>
中的value可以被用作$ {someVar}。
Profiles使用:
是一种定义多种环境配置的方式,主要用来替换配置文件中一些常量和url等等(直接就是${xxx}),但是不能直接在JAVA中使用,如果JAVA中要用,需要在配置文件中中转一下
//id为test,打包的时候会用到
<id> test </ id>
//此处代表未激活
<activation>
<activeByDefault>false</activeByDefault>
</activation>