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>