1 聲明 profile
<profiles>
<profile>
<id>local</id>
<properties> <package.environment>local</package.environment> </properties>
<activation> <!-- 默認激活這個配置 --> <activeByDefault>true</activeByDefault> </activation>
</profile>
<profile>
<id>product</id>
<properties> <package.environment>product</package.environment> </properties>
</profile>
</profiles>
2 聲明war plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive> <addMavenDescriptor>false</addMavenDescriptor> </archive>
<!-- 部署在百度雲 bae 上,一定要叫 ROOT.war -->
<!-- 雖然 IDEA 工具報提示警告,但是可以不理會,不影響使用 -->
<warName>ROOT</warName>
<webResources>
<resource>
<directory>src/main/resources/config/${package.environment}</directory>
<targetPath>WEB-INF/classes/config</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
warName :指定了打好包的名字;
webResources 下 resource 下 directory :配置真正使用的資源文件存放的位置,通常這個位置不是一個標准 Web 項目應該存放資源文件的位置;
webResources 下 resource 下 targetPath:將上一步 directory 中配置的文件目錄下的文件都拷貝到這個目錄下;‘
webResources 下 resource 下 filtering:開啟打包之前將 directory 下的文件拷貝(覆蓋)到 targetPath 下這種配置。
mvn clean package -webwar -Pro
