Maven 常用命令详解

常用命令

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的几种方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值