序:接触甚少,期望提高。写在这里也作为下个阶段了解的目标。<o:p></o:p>
1.下载:http://maven.apache.org/download.html<o:p></o:p>
2.安装,配置:解压缩,配置环境变量中加入:MAVEN_HOME,值为maven的解压缩目录。在path环境变量后加上,maven 解压缩目录下的bin文件目录。其它的好像不用么配置,可以改一下包的存放地方,还有选择下载包的地址。保持默认也可以,包的默认存放路径为${local user}/.m2/下面,下面是配置的官方文档。<o:p></o:p>
- Configuring Maven <o:p></o:p>
- Configuring a HTTP Proxy<o:p></o:p>
检测:在doc下面运行:mvn -v可以能查看maven版本号,就表明环境变量配置成功。可以通过mvn -h来使用maven的指令帮助查看<o:p></o:p>
3.使用:(这里简要介绍一个项目流程)<o:p></o:p>
· 建立工程
指令:mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app 。“com.mycompany.app”是你的工程的package的路径层次。“my-app”为工程名字,其它的固定。 <o:p></o:p>
· maven周期<o:p></o:p>
o build工程<o:p></o:p>
指令:mvn compile
第一次运行会下载很多jar包,而且机器负荷会很重。运行这个命令需要在pom.xml相同目录下面, 这个编译只编译主程序,不会编译test下面的程序。如果需要单独编译test,请运行:
指令:mvn test-compile
compile之后会生成target文件夹,主程序编译在classes下面,测试程序放在test-classes下
o 安装<o:p></o:p>
mvn install和mvn clean install指令。当你通过建立工程的时候,就在默认用户文件下面生成了工程文件夹,并生成了一个pom.xml的文件,这个里面是用来配置工程需要的包以及一些其它很多很麻烦的东东(还不是么熟悉)。运行前面两个指令的是要先cd 到该工程目录下面,就是在能看到pom.xml这个文件的文件夹目录,再运行。<o:p></o:p>
o 以下给出Maven提供的构建生命周期列表(来自:http://kenter1643.iteye.com/blog/100360):
validate<o:p></o:p> | validate the project is correct and all necessary information is available.<o:p></o:p> |
generate-sources<o:p></o:p> | generate any source code for inclusion in compilation.<o:p></o:p> |
process-sources<o:p></o:p> | process the source code, for example to filter any values.<o:p></o:p> |
generate-resources<o:p></o:p> | generate resources for inclusion in the package.<o:p></o:p> |
process-resources<o:p></o:p> | copy and process the resources into the destination directory, ready for packaging.<o:p></o:p> |
compile<o:p></o:p> | compile the source code of the project.<o:p></o:p> |
process-classes<o:p></o:p> | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.<o:p></o:p> |
generate-test-sources<o:p></o:p> | generate any test source code for inclusion in compilation.<o:p></o:p> |
process-test-sources<o:p></o:p> | process the test source code, for example to filter any values.<o:p></o:p> |
generate-test-resources<o:p></o:p> | create resources for testing.<o:p></o:p> |
process-test-resources<o:p></o:p> | copy and process the resources into the test destination directory.<o:p></o:p> |
test-compile<o:p></o:p> | compile the test source code into the test destination directory<o:p></o:p> |
test<o:p></o:p> | run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.<o:p></o:p> |
package<o:p></o:p> | take the compiled code and package it in its distributable format, such as a JAR.<o:p></o:p> |
pre-integration-test<o:p></o:p> | perform actions required before integration tests are executed. This may involve things such as setting up the required environment.<o:p></o:p> |
integration-test<o:p></o:p> | process and deploy the package if necessary into an environment where integration tests can be run.<o:p></o:p> |
post-integration-test<o:p></o:p> | perform actions required after integration tests have been executed. This may including cleaning up the environment.<o:p></o:p> |
verify<o:p></o:p> | run any checks to verify the package is valid and meets quality criteria.<o:p></o:p> |
install<o:p></o:p> | install the package into the local repository, for use as a dependency in other projects locally.<o:p></o:p> |
deploy<o:p></o:p> | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.<o:p></o:p> |