maven profile的不同激活方法

3)Profiles还可以基于detect到的build environment 的state来自动激活,而不需要象上面2种方式显式激活。这只需要在profile定义时使用<activation> element。如:
<profiles>
 <profile>
    <activation>
      <jdk>1.4</jdk>
    </activation>
    ...
 </profile>
</profiles>
上面的代码表示:如果JDK version start with 1.4 (eg. "1.4.0_08", "1.4.2_07", "1.4"),该profile会被激活
 
<profiles>
 <profile>
    <activation>
      <property>
        <name>debug</name>
      </property>
    </activation>
    ...
 </profile>
</profiles>
上面的代码表示:如果存在system propertie “debug”,该profile会被激活。为了激活它,输入的命令类似于:
mvn groupId:artifactId:goal –Ddebug
 
<profiles>
 <profile>
    <activation>
      <property>
        <name>environment</name>
        <value>test</value>
      </property>
    </activation>
    ...
 </profile>
</profiles>
上面的代码表示:如果存在system propertie “environment”的值为test,该profile会被激活。为了激活它,输入的命令类似于:
mvn groupId:artifactId:goal -Denvironment=test


4)Profiles还可以基于OS setting来自动激活
<profiles>
 <profile>
    <activation>
      <os>
      <name>Windows XP</name>
      <family>Windows</family>
      <arch>x86</arch>
      <version>5.1.2600</version>
    </os>
        </activation>
 ...
 </profile>
</profiles>
            上面的代码表示:如果OS为windows xp,该profile会被激活
 
5)根据某个file不存在而激活profile。例如下面定义的profile是在target/generated-sources/axistools/wsdl2java/org/apache/maven不存在时激活
<profiles>
 <profile>
    <activation>
      <file>
        <missing>target/generated-sources/axistools/wsdl2java/org/apache/maven</missing>
      </file>
    </activation>
    ...
 </profile>
</profiles>
 
 
使用Profiles时要注意的2个问题
 
第一、external properties
 
不是定义在pom.xml里的properties都称为external properties。举例说明最明了:
pom.xml:
<project>
 ...
 <build>
    <plugins>
      <plugin>
        <groupId>org.myco.plugins</groupId>
        <artifactId>spiffy-integrationTest-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <appserverHome>${appserver.home}</appserverHome>
        </configuration>
      </plugin>
      ...
    </plugins>
 </build>
 ...
</project>
 
~/.m2/settings.xml
<settings>
 ...
 <profiles>
    <profile>
      <id>appserverConfig</id>
      <properties>
        <appserver.home>/path/to/appserver</appserver.home>
      </properties>
    </profile>
 </profiles>
 
 <activeProfiles>
    <activeProfile>appserverConfig</activeProfile>
 </activeProfiles>
 ...
</settings>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值