一、maven 生命周期
简化的生命周期
validate
确认项目是否正确- compile 编译项目的源码
- test 测试
- package 编译后,进行打包
verify
对结果进行检查- install 将软件包安装到本地仓库
deploy
远程共享
生命周期详情
清洁(clean) clean:clean
默认生命周期绑定-打包ejb/ejb3/jar/par/rar/war
流程资源(process-resources) resources:resources
编译(compile) compiler:compile
流程测试资源(process-test-resources) resources:testResources
测试编译(test-compile) compiler:testCompile
测试(test) surefire:test
打包(package) ejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war
安装(install) install:install
部署(deploy) deploy:deploy
默认生命周期绑定-打包ear
生成资源(generate-resources) ear:generate-application-xml
流程资源(process-resources) resources:resources
打包(package) ear:ear
安装(install) install:install
部署(deploy) deploy:deploy
默认生命周期绑定-打包maven-plugin
生成资源(generate-resources) plugin:descriptor
流程资源(process-resources) resources:resources
编译(compile) compiler:compile
流程测试资源(process-test-resources) resources:testResources
测试编译(test-compile) compiler:testCompile
测试(test) surefire:test
打包(package) jar:jar and plugin:addPluginArtifactMetadata
安装(install) install:install
部署(deploy) deploy:deploy
默认生命周期绑定-包装pom
打包(package) site:attach-descriptor
安装(install) install:install
部署(deploy) deploy:deploy
网站生命周期绑定
网站(site) site:site
网站部署(site-deploy) site:deploy
二、标准目录
- src/main/java 应用库来源
- src/main/resources 应用库资源
- src/main/filters 资源过滤文件
- src/main/webapp web app 文件
- src/test/java 测试来源
- src/test/resources 测试资源
- src/test/filters 资源过滤
- src/it 集成测试
三、示例说明
// 举几个打包插件的例子
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.directory}/config</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>application.yml</include>
<include>application-dev.yml</include>
<include>application-prod.yml</include>
<include>logback-spring.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
以上面打包插件为例,首先我看先要看当前插件执行的生命周期。 <phase>package</phase> 在 package 阶段触发