首先在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>
<id>test</id>
<package.environment>test</package.environment>
</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