Maven构建Profile

1);profile可以构建不同的环境,让开发,产品环境给以管理。

2):pom.xml中的profiles元素,它包含了一个或者多个profile元素。由于profile覆盖了pom.xml中的默认设置,profiles通常是pom.xml中的最后一个元素。例如:

<profiles>
   <profile>
      <id>production</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <debug>false</debug>
              <optimize>true</optimize>
            </configuration>
          </plugin>
        </plugins>
      </build>
   </profile>
</profiles
每个每个profile必须要有一个id元素,mvn clean install -Pproduction 可以通过该命令调用。profile几乎可以覆盖pom.xml的所有元素。

2.用Profile激活动态包含子模块:

<pre name="code" class="html"><profiles>
   <profile>
    <id>jdk16</id>
    <activation>
        <activeByDefault>false</activeByDefault>#
       <jdk>1.6</jdk> 
       <property> 
             <name>!environment.type</name> 
        </property> 
      </activation>
    <modules>
      <module>simple-script</module>
   </modules>
   </profile>
</profiles>


 上代码中activation为激活因子,即当jdk为1.6开头是才会构建子模块。activeByDefault默认是否激活的配置,property属性缺失激活。 

如果你开始大量使用Maven profile,你会希望将profile从POM中分离,使用一个单独的文件如profiles.xml。你可以混合使用定义在pom.xml中和外部profiles.xml文件中的profile。只需要将profiles元素放到/usr/local/hudson/hudson-home/jobs/mavenguide-zh-to-production/workspace/content-zh目录下的profiles.xml文件中,然后照

常运行Maven就可以。

3.settings profile:

1)项目profile关心于覆盖某个项目的配置,而settings profile可以应用到所有你使用Maven构建的项目。

2)可以在两个地方定义settings profile:定义在~/.m2/settings.xml中的用户特定settings profile,或者定义在/usr/local/maven/conf/settings.xml中的全局settings profile

3)setting profile的默认激活配置

<settings>
  <activeProfiles>
     <activeProfile>dev</activeProfile>
  </activeProfiles>
</settings>

该设置只会激活settings profile,不会激活id匹配的项目profile

列出活动的Profile命令:mvn help:active-profiles

4.setting profile中设定特定的激活值方式

<settings>
    <profiles>
<span style="white-space:pre">	</span><profile>
<span style="white-space:pre">	</span><activation>
<span style="white-space:pre">		</span><activeByDefault>true</activeByDefault>
<span style="white-space:pre">	</span></activation>
<span style="white-space:pre">	</span><properties>
<span style="white-space:pre">	</span>     <environment.type>dev</environment.type>
<span style="white-space:pre">	</span></properties>
<span style="white-space:pre">	</span></profile>
    </profiles>
</settings

4.pom.xml的配置激活定义

<activation>
   <property>
     <name>environment.type</name>
     <value>dev</value>
   </property>
</activation>





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值