1.-D代表(Properties属性)
使用命令行设置属性-D的正确方法是:
mvn -DpropertyName=propertyValue clean package
如果propertyName不存在pom.xml,它将被设置。
如果propertyName已经存在pom.xml,其值将被作为参数传递的值覆盖-D。
如果要发送多个变量,请使用多个空格分隔符加-D:
mvn -DpropA=valueA -DpropB=valueB -DpropC=valueC clean package
例:
如果你的pom.xml如下:
<properties>
<title>good</ title >
</properties>
那么在这个执行过程中mvn -Dtitle=helloword clean package会覆盖title的值,具有如下效果:
<properties>
<title>helloword</title >
</properties>
2.-P代表(Profiles配置文件)
也就是说在<profiles>指定的<id>中,可以通过-P进行传递或者赋值。
例如如下:
<profiles>
<profile>
<!-- 本地开发环境:develop -->
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 测试环境 test -->
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
</profile>
<profile>
<!-- 生产环境 product -->
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
</properties>
</profile>
<!-- UAT -->
<profile>
<!-- 准生产环境uat -->
<id>uat</id>
<properties>
<profiles.active>uat</profiles.active>
</properties>
</profile>
</profiles>
执行mvn clean compile package -Pprod,走的生产环境分支
关注我们,精彩属于你





