Maven中的-D(Properties屬性)和-P(Profiles配置檔案)
阿新 • • 發佈:2019-01-09
-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為觸發配置檔案。
總結:
更多的參考Maven幫助文件:
Google搜尋關鍵字:maven d flag