一、Maven生命周期
- clean: 清除构建目录
- validate: 检查工程配置是否正确,完成构建过程的所有必要信息是否能够获取到。
- compile: 编译当前源码
- test: 使用适当的单元测试框架(例如JUnit)运行测试。
- package: 获取编译后的代码,并按照可发布的格式进行打包,例如 JAR、WAR 或者 EAR 文件
- verify: 运行检查操作来验证工程包是有效的,并满足质量要求。
- install: 安装工程包到本地仓库中,该仓库可以作为本地其他工程的依赖。
- site: 创建新的报告文档、部署站点等
- deploy: 拷贝最终的工程包到远程仓库中,以共享给其他开发人员和工程。
二、简述
Maven官网文档http://maven.apache.org
What is a POM?
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that >contains information about the project and configuration details used by Maven to build the >project. It contains default values for most projects. Examples for this is the build directory, >which is
target
; the source directory, which issrc/main/java
; the test source directory, which >issrc/test/java
; and so on. When executing a task or goal, Maven looks for the POM in the >current directory. It reads the POM, gets the needed configuration information, then executes >the goal.
Some of the configuration that can be specified in the POM are the project dependencies, the >plugins or goals that can be executed, the build profiles, and so on. Other information such as >the project version, description, developers, mailing lists and such can also be specified.
POM是Maven依赖的包含当前项目信息以及项目详细配置的XML文件, 即Project Object Module 项目对象模型,是Maven对项目进行管理的依赖。
三、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>org.codehaus.mojo</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
model 4.0.0是目前Maven2&3唯一支持的解析版本,可以视其为固定节点。
version##
- SNAPSHOT:快照版本
- ALPHA:内测版本
- BETA:公测版本
- RELEASE:稳定版本
- GA:正式发布
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>
</project>
1.基础配置信息
<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">
<!-- pom模型版本,maven2和3只能为4.0.0-->
<modelVersion>4.0.0</modelVersion>
<!-- 项目的组ID,用于maven定位-->
<groupId>com.company.bank</groupId>
<!-- 项目ID,通常是项目的名称,唯一标识符-->
<artifactId>parent</artifactId>
<!-- 项目的版本-->
<version>0.0.1-SNAPSHOT</version>
<!-- 项目的打包方式-->
<packaging>war</packaging>
<project>
pom.xml文件的最外层标签是project标签,该标签定义了如下属性:
-
xmlns
属性:表明了该标签下元素的默认命名空间是:http://maven.apache.org/POM/4.0.0,xml文件中,定义命名空间的格式为:xmlns:namespace-prefix="namespaceURI",而定义默认命名空间的格式为:xmlns="namespaceURI";*xmlns:xsi
属性:定义了一个namespace-prefix,其代表的命名空间URI为:http://www.w3.org/2001/XMLSchema-instance,定义该命名空间主要是为了更方便的使用其所代表的命名空间中的schemaLocation属性;其中,使用xsi作为namespace-prefix,并不是硬性规定,只是一种通用的选择,当然也可以改成别的命名;*xsi:schemaLocation
属性:该属性的使用格式为:xsi:schemaLocation="namespaceURI1 schemaURI1 namespaceURI2 schemaURI2 ..."
,这里是说使用schemaURI1所对应的schema文件,校验命名空间namespaceURI1下的元素是否符合XML语法规范,后面的则是以此类推。
网友评论