<profiles>
<profile>
<!--不同环境Profile的唯一id-->
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>testjndi</id>
<properties>
<env>testjndi</env>
</properties>
</profile>
</profiles>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--打包时先排除掉三个文件夹-->
<excludes>
<exclude>dev/*</exclude>
<exclude>prod/*</exclude>
<exclude>test/*</exclude>
<exclude>testjndi/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/${env}</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<warSourceExcludes>src/main/resources/META-INF/**</warSourceExcludes>
<packagingExcludes>WEB-INF/classes/META-INF/**</packagingExcludes>
<webResources>
<resource>
<directory>src/main/resources/META-INF/resources</directory>
<filtering>true</filtering>
<targetPath>/</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
注意在勾选对应环境后,需要刷新一下pom后再重新启动项目,这里的项目使用的是Tomcat的方式启动