maven

Profile

2017-08-07  本文已影响16人  zlcook

帮助命令

mvn help:active-profiles
mvn help:all-profiles

maven属性

profile种类

开启资源过滤

资源文件过滤

<build>
     <resources>
            <resource>
                <directory>{project.basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
    <!-- 对sql资源文件关闭资源过滤-->
         <resource>
                <directory>{project.basedir}/src/main/sql</directory> 
                <filtering>false</filtering>
            </resource>
    </resources>
...
   <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${maven-resources-plugin.version}</version>
                <configuration>
                    <encoding>${project.encoding}</encoding>
                </configuration>
            </plugin>
    </plugins>
</build>

web资源文件过滤

激活profile6种方式

 <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
        </profile>
       <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
 <!--通过系统属性激活,当系统中存在某个属性或属性等于某个值时激活-->
        <profile>
            <id>prod</id>
           <activation>
                <property>
                    <name>server</name>
                    <value>x</value>
                </property>
            </activation>
            <properties>
                <profiles.active>prod</profiles.active>
            </properties>
        </profile>
      <profile>
            <id>jdk1.6</id>
            <activation>
                <property>
                    <name>jdk1.6</name>
                </property>
            </activation>
            <properties>
                <java.version>1.6</java.version>
            </properties>
        </profile>
    </profiles>
  <profiles>
    <profile>
     .....
    <id>artifactory</id>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
<profiles>
        <profile>
            <id>dev</id>
            <activation>
             <file>
                   <missing>x.properties</missing>
                   <exists>y.properties</exists>
             </file>
            </activation>
            <properties>
                .....
            </properties>
        </profile>
<profiles>
<profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
        </profile>
<profiles>

案例

<settings>
<mirrors>
     <!-- 代理central远程仓库 -->
     <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror> 
  </mirrors>

  <profiles>
     <profile>
      <repositories>
        <repository>
            <id> maven2 repository snapshots</id>
            <name> maven2 repository-snapshots</name>
            <url>公司私服地址</url>
        </repository>
        <repository>
            <id> maven2 repository releases</id>
            <name>maven2 repository-releases</name>
            <url>公司私服地址</url>
        </repository>
     
      </repositories>
      <pluginRepositories>
       
        <pluginRepository>
          <id> maven2 plugin repository releases</id>
          <name> maven2 repository-releases</name>
          <url>公司私服地址</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>

  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>

</settings>
上一篇下一篇

猜你喜欢

热点阅读