首先在pom.xml中加入



<properties>

       ....

       <!-- Default environment-->

       <package.environment>test</package.environment>

</properties>


2 配置profiles环境

<profiles>

       <profile>

           <id>product</id>

           <properties>

               <package.environment>product</package.environment>

           </properties>

       </profile>

       <profile>

           <id>test</id>

           <properties>

               <package.environment>test</package.environment>

           </properties>

       </profile>

   </profiles>


3 根据不同的环境查找不同path下的资源文件

<plugin>

               <groupId>org.apache.maven.plugins</groupId>

               <artifactId>maven-war-plugin</artifactId>

               <configuration>

                   <archive>

                       <addMavenDescriptor>false</addMavenDescriptor>

                   </archive>

                   <webResources>

                       <resource>

                           <!-- this is relative to the pom.xml directory -->

                           <directory>src/main/resources/${package.environment}</directory>

                           <targetPath>WEB-INF/classes</targetPath>

                           <filtering>true</filtering>

                       </resource>

                   </webResources>

                   <!-- Exclude the resource files-->

                   <warSourceExcludes>src/main/resources/**</warSourceExcludes>

               </configuration>

           </plugin>


4 使用命令进行package   --  mvn package -PXXXX