版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1、三套生命周期 对于maven的生命周期来说,共有三个相互独立的生命周期,分别是clean、default、site。clean生命周期目的是清理项目,default生命周期目的是构建项目,而site生命周期目的是建立项目站点。 每个生命周期分别包含一些阶段,这些阶段是有顺序的,并且后面的阶段依赖于前面的阶段。如clean生命周期包含pre-clean、clean和post-clean三个阶段,如果执行clean阶段,则会先执行pre-clean阶段。 较之于生命周期阶段有前后依赖关系,三套生命周期本身是相互独立的,用户可以仅调用clean生命周期的某个阶段,也可以不执行clean周期,而直
2、接执行default生命周期的某几个阶段。2、clean生命周期 clean生命周期包含三个阶段,主要负责清理项目,如下:pre-cleanexecutes processes needed prior to the actual project cleaningcleanremove all files generated by the previous buildpost-cleanexecutes processes needed to finalize the project cleaning3、default生命周期 default生命周期定义了真正构建时所需要执行的所有步骤,包含的
3、阶段如下:validatevalidate the project is correct and all necessary information is available.initializeinitialize build state, e.g. set properties or create directories.generate-sourcesgenerate any source code for inclusion in cess-sourcesprocess the source code, for example to filter any
4、values.generate-resourcesgenerate resources for inclusion in the cess-resourcescopy and process the resources into the destination directory, ready for pilecompile the source code of the cess-classespost-process the generated files from compilation, for example to
5、do bytecode enhancement on Java classes.generate-test-sourcesgenerate any test source code for inclusion in cess-test-sourcesprocess the test source code, for example to filter any values.generate-test-resourcescreate resources for cess-test-resourcescopy and process the re
6、sources into the test destination directory.test-compilecompile the test source code into the test destination directoryprocess-test-classespost-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above.testrun tests using a
7、suitable unit testing framework. These tests should not require the code be packaged or deployed.prepare-packageperform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above)packagetake the
8、 compiled code and package it in its distributable format, such as a JAR.pre-integration-testperform actions required before integration tests are executed. This may involve things such as setting up the required egration-testprocess and deploy the package if necessary into an environ
9、ment where integration tests can be run.post-integration-testperform actions required after integration tests have been executed. This may including cleaning up the environment.verifyrun any checks to verify the package is valid and meets quality criteria.installinstall the package into the local re
10、pository, for use as a dependency in other projects locally.deploydone in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.4、site生命周期 siet生命周期的目的是建立和发布项目站点,maven能够基于POM所包含的信息,自动生成一个友好的站点,方便团队交流和发布项目信息,包含的阶段如下:pre-
11、siteexecutes processes needed prior to the actual project site generationsitegenerates the projects site documentationpost-siteexecutes processes needed to finalize the site generation, and to prepare for site deploymentsite-deploydeploys the generated site documentation to the specified web server5
12、、命令行与生命周期从命令行执行maven任务的最主要方式就是调用maven的生命周期阶段。需要注意的是,各个生命周期是相互独立的,而一个生命周期的阶段是有前后依赖关系的。例子如下: 1、$mvn clean :该命令调用clean生命周期的clean阶段。实际执行的阶段为clean生命周期的pre-clean和clean阶段。 2、$mvn test:该命令调用default生命周期的test阶段。实际调用的是default生命周期的validate、initialize等,直到test的所有阶段。 3、$mvn clean install:该命令调换用clean生命周期的clean阶段和de
13、fault生命周期的instal阶段。6、插件目标 maven的核心仅仅定义了抽象的生命周期,具体的任务是交由插件完成的,插件以独立的形式存在。 对于插件本身,为了能够复用代码,它往往能够完成多个任务。如maven-dependency-plugin有十多个目标,每个目标对应了一个功能,如 dependency:analyze、 dependency:tree和dependency:list。这是一种通用的写法,冒号前面是插件前缀,后面是该插件的目标。7、插件绑定maven的生命周期与插件相互绑定,用以完成实际的构建任务。具体而言,是生命周期的阶段与插件的目标相互绑定,已完成某个具体的构建任务
14、。例如项目编译这一任务,它对应了default生命周期的compile阶段,而maven-compiler-plugin这一插件的compile目标能够完成该任务,因此将他们绑定。7.1内置绑定maven在核心为一些主要的生命周期接到绑定了很多插件的目标,如下: clean和site生命周期相对简单。cleanclean:cleansitesite:sitesite-deploysite:deploy default生命周期与插件目标的绑定关系有点复杂一些。这是因为对于任何项目来说,例如jar项目和war项目,他们的项目清理和站点生成任务是一样的,不过构建过程会有区别。例如jar项目需要打成j
15、ar包,而war项目需要打成war包。由于项目的打包类型会影响构建的具体过程,因此,default生命周期的阶段与插件目标的绑定关系有项目打包类型所决定的,打包类型是通过pom中的packaging元素定义的。最常见的打包类型是jar,它也是默认的打包类型。基于该打包类型,default生命周期的内置绑定关系如下:process-resourcesresources:resourcescompilecompiler:compileprocess-test-resourcesresources:testResourcestest-compilecompiler:testCompiletestsu
16、refire:testpackageejb:ejborejb3:ejb3orjar:jarorpar:parorrar:rarorwar:warinstallinstall:installdeploydeploy:deploy7、2自定义绑定 除了内置绑定以为,用户还能够自己选择奖某个插件目标绑定到生命周期的某个阶段以执行更多更特色的任务。htmlview plaincopyprint? 1. 2. 3. org.apache.maven.plugins4. maven-resources-plugin5. 2.66. 7. true8. GBK9. 10. exe11. zip12. vbs
17、13. sh14. 15. 16. 17. 18. copy-resources19. validate20. 21. copy-resources22. 23. 24. true25. $project.build.directory26. 27. agentmanager.jsmooth28. assembly.xml29. 30. 31. 32. src/main/resources/33. true34. 35. 36. 37. 38. 39. 如上图定义了一个id为copy-resources的任务,绑定到default生命周期的validate阶段,绑定的插件为maven-reso
18、urces-plugin,插件目标为copy-resources。即用插件的copy-resources功能来实现项目资源文件的拷贝。htmlview plaincopyprint? 1. 2. 3. org.apache.maven.plugins4. maven-dependency-plugin5. 2.16. 7. 8. copy9. install10. 11. copy-dependencies12. 13. 14. lib15. 16. 17. 18. 同上,定义了一个id为copy的任务,利用插件maven-dependency-plugin的copy-dependencies
19、目标绑定到default生命周期的install阶段,来实现项目依赖的jar包的自动复制。当插件目标被绑定到不同的生命周期阶段时候,其执行顺序会有生命周期阶段的先后顺序决定的。如果多个目标被绑定到同一个阶段,他们的执行顺序是由插件声明的先后顺序决定目标的执行顺序。8、插件配置用户可以配置插件目标的参数,进一步调整插件目标所执行的任务。8、1命令行插件配置如 $mvn install -Dmaven.test.skip=true 的意义即跳过测试步骤。 参数-D的java自带的,其功能是通过命令行设置一个java系统属性,maven简单地重用了该参数以实现插件参数的配置。8、2pom中插件全局配
20、置如项目编译使用1.6版本的源文件,生成与JVM1.6兼容的字节码文件,如下:htmlview plaincopyprint? 1. 2. org.apache.maven.plugins3. maven-compiler-plugin4. 2.3.25. 6. 1.67. 1.68. 9. 9、获取插件描述信息 $mvn help:describe-Dplugin=org.apache.maven.plugins:maven-compiler-plugin:2.1 来获取插件的详细信息 可以简化为: $mvn help:describe-Dplugin=compiler 如果仅仅描述插件目标
21、的信息,可以加上goal参数: $mvn help:describe-Dplugin=compiler-Dgoal=compile 如果想输出更详细的信息,可以加上detail参数: $mvn help:describe-Dplugin=compiler-Ddetail(二):灵活的构建原文地址:参考官方url:/guides/index.html一个优秀的构建系统必须足够灵活,应该能够让项目在不同的环境下都能成功构建。maven为了支持构建的灵活性,内置了三大特性,即:属性、profile和资源过滤。1、maven属性maven属性分6类: 1、内
22、置属性:如$basedir表示项目根目录,$version表示项目版本 2、POM属性:用户可以引用pom文件中对应的值。如: $basedir 项目根目录 $project.build.directory 构建目录,缺省为target$project.build.outputDirectory 构建过程输出目录,缺省为target/classes$project.build.finalName 产出物名称,缺省为$project.artifactId-$project.version$project.packaging 打包类型,缺省为jar$project.xxx 当前pom文件的任意节点
23、的内容 3、自定义属性:用户可以在pom的元素下自定义maven属性。 4、setting属性:用户可以使用以settings开头的属性引用settings.xml中xml元素的值,如$settings.localRepository指向用户本地仓库的地址。 5、java系统属性:maven可以使用当前java系统的属性,如$user.home指向了用户目录。 6、环境变量属性:所有环境变量都可以使用以env.开头的属性。如:$env.JAVA_HOE。2、资源过滤 这里所谓的资源:也就就是指src/main/resources和src/test/resources文件下的所有文件,默认情况下
24、,这些文件会被复制到classpath下面,即target/classes下面。 所谓资源过滤,就是过滤这些文件夹下面的文件里面的内容,看里面的maven变量是否需要替换。默认情况下,只有pom.xml里面的变量才会被替换,资源文件是不会被过滤的,但是可以设置,如下:htmlview plaincopyprint? 1. 2. agentmanager3. src/main/java4. 5. 6. 7. src/main/resources8. 9. */jre.zip10. */jre.tar11. agentmanager.jsmooth12. assembly.xml13. 14. $
25、project.build.directory15. 16. 17. src/main/resources/conf18. $basedir/conf19. true20. 21. 22. 如pertiescssview plaincopyprint? 1. jdbc.driverClassName=$db.driver2. jdbc.url=$db.url3. jdbc.username=$db.user4. jdbc.password=$db.pwdprofile文件htmlview plaincopyprint? 1. 2. 3. dev4. 5. oracle.jdbc.driver.OracleDriver6. jdbc:oracle:thin::1521:dbname7. username8. userpwd9.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年昆明市第一人民医院合同制招聘真题及答案
- 2026及未来5年中国热流道管坯模具数据监测研究报告
- DB62∕T 3342-2026 装配式抗菌铝合金骨架墙体应用技术标准
- DB62∕T 3283-2024 结构侧预埋式悬挑脚手架安全技术标准
- DB62∕T 25-3074-2013 岩棉板外墙外保温系统应用技术规程
- 2026年医务人员穿脱隔离衣流程试题(附答案)
- 感恩有您 一路同行 教师节主题班会
- 企业绩效偏差风险管控设计
- 心脑血管疾病早预防知识讲座医学课件
- 烟囱筒壁工程安全监理实施细则
- 2026年武汉市中考语文试卷(含答案)
- 司法辅助人员笔试完整题型、分值及真题答案
- 陕西科技大学教师专业技术职务评审工作实施办法(试行)
- 高中历史课件-第6课-全球航路的开辟
- 2026年无人机应用技术考试测试题库附参考答案详解(完整版)
- 2026高考英语考前高频词汇+作文万能模板
- 肿瘤患者输血支持(医学课件)
- 2026中国土地用途管制制度创新与实施效果评估报告
- GB/T 8325-2026塑料聚合物分散体和橡胶胶乳pH值的测定
- 三轴搅拌桩安全交底
- 农商行催收培训
评论
0/150
提交评论