-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> <theme>myDefaultTheme</theme> </properties>
那么在這個執行過程中mvn -Dtheme=halloween clean package
會覆蓋theme
的值,具有如下效果:
<properties> <theme>halloween</theme> </properties>
-P代表(Profiles配置文件)
也就是說在<profiles>指定的<id>中,可以通過-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 -Penv=test為觸發配置文件。
具體實踐例子,參考:http://www.cnblogs.com/EasonJim/p/6828743.html
總結:
更多的參考Maven幫助文檔:
http://books.sonatype.com/mvnref-book/reference/running-sect-options.html#running-sect-define-prop
Google搜索關鍵字:maven d flag