如何使用mvn -D通过命令行在Maven中设置(多个)属性? [英] How to use the mvn -D to set (multiple) properties in Maven via command line?

查看:1022
本文介绍了如何使用mvn -D通过命令行在Maven中设置(多个)属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Maven中使用mvn -D?如何使用它设置一个(或多个)属性?

How to use the mvn -D in maven? How to set a property (or multiple properties) using it?

mvn -D是否有任何官方文章?

Are there any official articles for mvn -D?

我找不到一个.谢谢.

推荐答案

使用-D通过命令行设置属性的正确方法是:

The proper way to set a property via command-line using -D is:

mvn -DpropertyName=propertyValue clean package

  • 如果pom.xml中不存在propertyName,它将被设置.
  • 如果propertyName中已经存在propertyName,则其值将被通过-D作为参数传递的值覆盖.
    • If propertyName doesn't exist in the pom.xml, it will be set.
    • If propertyName already exists in the pom.xml, its value will be overwritten by the one passed as argument via -D.
    • 要发送多个变量,请使用多个以空格分隔的-D s:

      To send multiple variables, use multiple space delimited -Ds:

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

      您可以在《 Maven:完整参考》 中查看有关属性的更多详细信息.更具体地说,在以下部分中: 6.1. Maven命令行选项/6.1.1.定义属性 .

      You can check more details about properties in Maven: The Complete Reference. More specifically, in section: 6.1. Maven Command Line Options/6.1.1. Defining Properties.

      如果您在pom.xml中:

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

      然后mvn -Dtheme=halloween clean package将在此执行期间覆盖theme的值,具有效果,就像您具有的一样:

      Then mvn -Dtheme=halloween clean package would overwrite themes value during this execution, having the effect as if you had:

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

      这篇关于如何使用mvn -D通过命令行在Maven中设置(多个)属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆