在多种环境下,配置文件难免出现,在自动化部署中,maven的使用还是比较广泛和稳定,在此记录下一些常见的配置。
Resource
profile
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<project.classifier>test</project.classifier>
</properties>
<build>
<filters>
<filter>test.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>dev</id>
<properties>
<project.classifier>dev</project.classifier>
</properties>
<build>
<filters>
<filter>dev.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>prod1</id>
<properties>
<project.classifier>prod1</project.classifier>
</properties>
<build>
<filters>
<filter>prod1.properties</filter>
</filters>
</build>
</profile>
</profiles>
WebResource
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<filters>
<filter>
${project.basedir}/${project.classifier}.properties
</filter>
</filters>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>path/to/filterfile</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
遇到的问题
在使用过程中,本地一切正常,但是部署到远程服务器时,js文件始终没有被过滤,耗尽了半天的时间,查询了各种情况,终无效果。当无意查看远程pom.xml文件时,意外发现<202c>诡异的代码,试着将对应的代码删除重写,奇迹出现了:)~