clean:清除maven的输出
Validate:验证工程是否正确,所有需要的资源是否可用。
Compile:编译项目的源代码。
test-compile:编译项目测试代码。
Test:使用已编译的测试代码,测试已编译的源代码。
Package:已发布的格式,如jar,将已编译的源代码打包。
integration-test:在集成测试可以运行的环境中处理和发布包。
Verify:运行任何检查,验证包是否有效且达到质量标准。
Install:把包安装在本地的repository中,可以被其他工程作为依赖来使用
Deploy:在整合或者发布环境下执行,将最终版本的包拷贝到远程的repository,使得其他的开发者或者工程可以共享
创建IDE文件 mvn eclipse:eclipse
关于pom.xml
a) 总览
<project> <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>
b) 基本信息
• groupId:项目或者组织的唯一标志,并且配置时生成的路径也是由此生成,如com.taobao.sportal生成的相对路径为:/com/taobao/sportal
• artifactId: 项目的通用名称
• version:项目的版本
• packaging: 打包的机制,如 jar,, ejb, war, ear, rar, par
• classifier: 分类
c) 依赖关系dependencies(依赖,继承,合成)
dependencyManagement:
用于父项目配置共同的依赖关系,主要配置依赖包相同因素,如版本,scope。
版本号在父项目pom.xml声明,便于统一控制各子项目的依赖
I依赖
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<type>jar</type>
<scope>test</scope>
<optional>true</optional>
</dependency>
……
</dependencies>
groupId, artifactId, version:描述了依赖的项目唯一标志
type:相应的依赖产品包形式,如jar,war
scope:用于限制相应的依赖范围,包括以下的几种变量:
• compile :默认范围,用于编译
• provided:类似于编译,但支持你期待jdk或者容器提供,类似于classpath
• runtime:在执行时,需要使用
• test:用于test任务时使用
• system:需要外在提供相应得元素。通过systemPath来取得
systemPath: 仅用于范围为system。提供相应的路径,非常不好用
optional: 标注可选,当项目自身也是依赖时。用于连续依赖时使用
可以设置独占性,解决版本冲突:
<dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-need</artifactId> <version>2.0</version> <exclusions> <exclusion> <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> </exclusion> </exclusions> </dependency>
表示项目maven-need需要maven-core,但不想引用maven-core
II继承
父项目的pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.taobao.sportal</groupId>
<artifactId>my-parent</artifactId>
<version>2.0</version>
<packaging>pom</packaging>
</project>
子项目pom.xml
<project> <modelVersion>4.0.0</modelVersion> <parent> <groupId> com.javaeye.sportal </groupId> <artifactId>my-parent</artifactId> <version>2.0</version> </parent> <artifactId>my-project</artifactId> </project>
III合成
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.taobao.sportal</groupId> <artifactId>my-parent</artifactId> <version>2.0</version> <modules> <module>my-project1<module> <module>my-project2<module> </modules> </project>
d)Build
<build> <defaultGoal>install</defaultGoal> <directory>${basedir}/target</directory> <finalName>${artifactId}-${version}</finalName> <!—资源 --> <resources> <resource> <targetPath>META-INF/common</targetPath> <filtering>false</filtering> <directory>${basedir}/src/main/java</directory> <includes> <include>*.xml</include> </includes> <excludes> <exclude>**/*.properties</exclude> </excludes> </resource> </resources> <testResources> <!--插件 --> <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> </plugins> ... </testResources> <!-- 过滤 --> <filters> <filter>filters/XX.properties</filter> </filters> ... </build>
defaultGoal: 定义默认的目标或者阶段。如install
directory: 编译输出的目录
finalName: 生成最后的文件的样式
filter: 定义过滤,用于替换相应的属性文件
resources:
resource的列表,用于包括所有的资源
targetPath: 指定目标路径,用于放置资源,用于build
filtering: 是否替换资源中的属性
directory: 资源所在的位置
includes: 样式,包括那些资源
excludes: 排除的资源
testResources: 测试资源列表
plugin:
extensions: true or false,是否装载插件扩展。默认false
inherited: true or false,是否此插件配置将会应用于poms,那些继承于此的项目
configuration: 指定插件配置
dependencies: 插件需要依赖的包
executions: 用于配置execution目标,一个插件可以有多个目标