Maven实战读书笔记(七):Maven常用功能

7.1、资源排除

<resources>
   <!-- 启动过滤,包含的文件会被过滤掉 -->
   <resource>
     <directory>src/main/resources</directory>
     <filtering>true</filtering>
     <includes>
       <include>src/main/resources/dev/*.*</include>
       <include>src/main/resources/local/*.*</include>
     </includes>
   </resource>
 
  <!-- 不启动过滤,包含的文件会被打包 -->
  <resource>
    <directory>src/main/resources</directory>
    <filtering>false</filtering>
    <includes>
      <include>*.xml</include>
      <include>*.properties</include>
    </includes>
  </resource>
 </resources>

7.2、环境区分

 <!-- 配置 -->
 <profiles>
    <!-- 开发环境 -->
    <profile>
     <id>dev</id>
     <activation>
       <activeByDefault>true</activeByDefault>
     </activation>
     <build>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <version>1.1</version>
         <executions>
           <execution>
             <phase>test</phase>
             <goals>
               <goal>run</goal>
             </goals>
             <configuration>
               <tasks>
                 <echo>Using dev</echo>
                 <copy file="src/main/resources/dev/systemParm.properties"
tofile="${project.build.outputDirectory}/systemParm.properties" />
               </tasks>
             </configuration>
           </execution>
         </executions>
       </plugin>
     </plugins>
   </build>
   </profile>

 <!-- 本地环境 -->
 <profile>
   <id>local</id>
   <build>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <version>1.1</version>
         <executions>
           <execution>
             <phase>test</phase>
             <goals>
               <goal>run</goal>
             </goals>
             <configuration>
             <tasks>
               <echo>Using local</echo>
               <copy file="src/main/resources/local/systemParm.properties"
tofile="${project.build.outputDirectory}/systemParm.properties" />
             </tasks>
           </configuration>
         </execution>
       </executions>
     </plugin>
     </plugins>
     </build>
     </profile>
 </profiles>

7.3.配置jdk版本—maven全局配置

<profile>    
   <id>JDK-1.8</id>
   <activation>
     <activeByDefault>true</activeByDefault>
     <jdk>1.8</jdk>
   </activation>
   <properties>
     <maven.compiler.source>1.8</maven.compiler.source>
     <maven.compiler.target>1.8</maven.compiler.target>
     <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
   </properties>
 </profile>
posted @ 2018-01-28 21:03  王小帅  阅读(176)  评论(0编辑  收藏  举报