zoukankan      html  css  js  c++  java
  • Maven中的-D(Properties属性)和-P(Profiles配置文件)

    -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>

    以上参考:http://stackoverflow.com/questions/17332857/how-to-use-the-mvn-d-to-set-multiple-properties-in-maven-via-command-line

    -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://stackoverflow.com/questions/17332857/how-to-use-the-mvn-d-to-set-multiple-properties-in-maven-via-command-line

    http://books.sonatype.com/mvnref-book/reference/running-sect-options.html#running-sect-define-prop

  • 相关阅读:
    JQuery的ajax函数执行失败,alert函数弹框一闪而过
    ThinkPHP5.1中数据查询使用field方法数组参数起别名时遇到的问题
    Linux Web服务器集群搭建
    三层架构之UI层
    Aircoinst 三层架构ASP.NET开源
    [教程]KALI LINUX 2.0 2019 更新国内源
    工厂模式
    Java 实现序列化和反序列化
    Java实现缓冲流 编码 & 解码
    Java使用IO流读取文件显示到控制台2
  • 原文地址:https://www.cnblogs.com/a-du/p/9663272.html
Copyright © 2011-2022 走看看