简体   繁体   English

如何使用mvn -D通过命令行在Maven中设置(多个)属性?

[英]How to use the mvn -D to set (multiple) properties in Maven via command line?

How to use the mvn -D in maven? 如何在maven中使用mvn -D How to set a property (or multiple properties) using it? 如何使用它设置属性(或多个属性)?

Are there any official articles for mvn -D ? mvn -D有官方文章吗?

I couldn't find one. 我找不到一个。 Thanks. 谢谢。

The proper way to set a property via command-line using -D is: 使用-D通过命令行设置属性的正确方法是:

mvn -DpropertyName=propertyValue clean package
  • If propertyName doesn't exist in the pom.xml , it will be set. 如果pom.xml中不存在propertyName ,则将设置它。
  • If propertyName already exists in the pom.xml , its value will be overwritten by the one passed as argument via -D . 如果propertyName已存在于pom.xml ,则其值将被通过-D作为参数传递的值覆盖

To send multiple variables , use multiple space delimited -D s: 要发送多个变量 ,请使用多个空格分隔的-D s:

mvn -DpropA=valueA -DpropB=valueB -DpropC=valueC clean package

You can check more details about properties in Maven: The Complete Reference . 您可以在Maven中查看有关属性的更多详细信息:完整参考 More specifically, in section: 6.1. 更具体地说,在以下部分: 6.1。 Maven Command Line Options/6.1.1. Maven命令行选项/ 6.1.1。 Defining Properties . 定义属性

Example: 例:

If you have in your pom.xml : 如果你有pom.xml

<properties>
    <theme>myDefaultTheme</theme>
</properties>

Then mvn -Dtheme=halloween clean package would overwrite theme s value during this execution, having the effect as if you had: 然后mvn -Dtheme=halloween clean package会在执行期间覆盖theme的值, 效果就像你有:

<properties>
    <theme>halloween</theme>
</properties>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM