初次使用Maven

管理项目构建整个过程的工具,使得项目的构建只需一条命令即可自动化完成。
哲学:Convention over configuration。Maven有很多约定,按照这些约定来,可以省掉很多配置。
比如对于开发的文件夹,就有如下约定:
src/main/javaApplication/Library sources
src/main/resourcesApplication/Library resources
src/main/filtersResource filter files
src/main/assemblyAssembly descriptors
src/main/configConfiguration files
src/main/webappWeb application sources
src/test/javaTest sources
src/test/resourcesTest resources
src/test/filtersTest resource filter files
src/siteSite
LICENSE.txtProject's license
NOTICE.txtNotices and attributions required by libraries that the project depends on
README.txtProject's readme

Maven把整个构建过程称为Lifecycle,Lifecycle由一系列Stage构成(即构建的主要阶段),每个Stage内可以包含一些tasks/goals。 而goal是由plugin来完成的,每个plugin可以完成一些goals。

1. Maven中已经内置了3种Lifecycle---default, clean and site,如 default Lifecycle包括以下Stages:
  • validate - validate the project is correct and all necessary information is available
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  • verify - run any checks to verify the package is valid and meets quality criteria
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
    执行时,只需输入mvn install,就会执行所有从validate到install的stage。

2. 如何将task绑定到stage中去:
使用package:POM element   <packaging>  Some of the valid packaging values are   jar,   war,   ear  and   pom. If no packaging value has been specified, it will default to   jar. 每种package就定义了在各个stage中绑定哪些task。
Default Lifecycle Bindings - Packaging ejb / ejb3 / jar / par / rar / war
process-resourcesresources:resources
compilecompiler:compile
process-test-resourcesresources:testResources
test-compilecompiler:testCompile
testsurefire:test
packageejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war
installinstall:install
deploydeploy:deploy

使用plugin来单独配置:POM in the   <plugins>

3. pom.xml文件:
定义该project的配置。Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified.
自己定义的pom文件将继承Maven定义好的Super POM 文件,该Super POM中定义了很多默认的设置。

4. Repository:
在pom文件中申明的dependency,Maven首先查看local repository中有没有该依赖的包,如果没有,则到一个remote repository中去下载(可以设置,默认是Maven的一个远程repository,可以配置为公司内部的一个服务器),然后放到local repository中。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值