常用命令
mvn clean 清除项目的生成结果
mvn package 打包项目生成jar/war文件
mvn test 运行测试
mvn install 安装jar至本地库
mvn -e 显示详细错误信息
mvn validate 验证工程是否正确,所有需要的资源是否可用
-Dmaven.test.skip=true 跳过测试
-Dmaven.tomcat.port=9090 指定端口
-Dmaven.test.failure.ignore=true 忽略测试失败
-D 和 -P 参数
-D 表示 Properties 属性
mvn -DpropertyName=propertyValue clean package
如果 propertyName 不存在于 pom.xml 文件中,它将被设置。如果 propertyName 已经存在 pom.xml 文件中,其值将被作为参数传递的值覆盖。
例如,现有 pom.xml 文件如下所示:
<properties>
<theme>myDefaultTheme</theme>
</properties>
那么在执行过程中 mvn -Dtheme=newValue clean package 会覆盖 theme 的值,具有如下效果:
<properties>
<theme>newValue</theme>
</properties>
要设置多个变量,请使用多个空格分隔符加-D:
mvn -DpropA=valueA -DpropB=valueB -DpropC=valueC clean package
-P 表示 Profiles 配置文件的属性
-P 代表 Profiles 配置文件的属性,也就是说在 指定的 中,可以通过-P进行传递或者赋值。
例如,现有 pom.xml 文件如下所示:
<profiles>
<profile>
<id>test</id>
...
</profile>
</profiles>
执行 mvn test -Ptest 会触发配置文件。
或者如下所示:
<profile>
<id>test</id>
<activation>
<property>
<name>env</name>
<value>test</value>
</property>
</activation>
...
</profile>
执行mvn test -Denv=test 为触发配置文件。
要设置多个变量,请使用逗号分隔开:
mvn test -Ptest01,test02
具体profile激活可参考:详解Maven profile配置管理及激活profile的几种方式