生命周期是指项目的构建过程,它包含了一系列的有序的阶段(phase),而一个阶段就是构建过程中的一个步骤。
Maven有一下三种标准的生命周期,最常用的是默认的Maven生命周期(default Maven lifecycly):
目标代表一个特定的任务,这有助于项目的建设和管理。目标可以被绑定到零个或多个生成阶段。一个没有绑定到任何构建阶段的目标的构建生命周期可以执行直接调用。执行的顺序取决于目标和构建阶段被调用的顺序。
执行mvn clean之后,maven的清洁生命周期由一下三个阶段组成:
下面我们将使用 maven-antrun-plugin:run进行调用clean生命周期。
执行 "mvn post-clean“之后,显示如下:
可以看到依次执行了 pre-clean、clean以及 post-clean。并且执行结束之后项目中target路径中的编译好的文件被删除。说明清洁成功。
默认生命周期是maven使用最多的生命周期,用于构建程序。它由一下23个阶段组成:
描述 | |
---|---|
validate | Validates whether project is correct and all necessary information is available to complete the build process. |
initialize | Initializes build state, for example set properties |
generate-sources | Generate any source code to be included in compilation phase. |
process-sources | Process the source code, for example, filter any value. |
generate-resources | Generate resources to be included in the package. |
process-resources | Copy and process the resources into the destination directory, ready for packaging phase. |
compile | Compile the source code of the project. |
process-classes | Post-process the generated files from compilation, for example to do bytecode enhancement/optimization on Java classes. |
generate-test-sources | Generate any test source code to be included in compilation phase. |
process-test-sources | Process the test source code, for example, filter any values. |
test-compile | Compile the test source code into the test destination directory. |
process-test-classes | Process the generated files from test code file compilation. |
test | Run tests using a suitable unit testing framework(Junit is one). |
prepare-package | Perform any operations necessary to prepare a package before the actual packaging. |
package | Take the compiled code and package it in its distributable format, such as a JAR, WAR, or EAR file. |
pre-integration-test | Perform actions required before integration tests are executed. For example, setting up the required environment. |
integration-test | Process and deploy the package if necessary into an environment where integration tests can be run. |
pre-integration-test | Perform actions required after integration tests have been executed. For example, cleaning up the environment. |
verify | Run any check-ups to verify the package is valid and meets quality criterias. |
install | Install the package into the local repository, which can be used as a dependency in other projects locally. |
deploy | Copies the final package to the remote repository for sharing with other developers and projects. |
当我们通过命令调用一个阶段的时候,比如说 mvn compile,这个阶段以及这个阶段之前的所有阶段都将被执行。根据打包的种类(JAR/WAR/EAR),每个阶段会绑定不同的goal。
执行 mvn compile,target路径下会多一个maven-status的文件夹,里面存放了编译的结果。控制台输出结果如下:
该阶段分为四个阶段:
运行 mvn site之后,log如下:
运行之后,会在target路径下生成一个site文件夹,里面包括很多文件,包括css,images以及一些项目描述文件。
原文:http://www.cnblogs.com/miniren/p/4638619.html