Maven 插件
maven-replacer-plugin
字符串替换插件:打包时替换某个文件中的此字符串为彼字符串
根据不同的环境使用不同的数据库IP
<build> <finalName>struts2</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <useCache>true</useCache> </configuration> <executions> <execution> <id>prepare-war</id> <phase>prepare-package</phase> <goals> <goal>exploded</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.google.code.maven-replacer-plugin</groupId> <artifactId>replacer</artifactId> <version>1.5.2</version> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>replace</goal> </goals> </execution> </executions> <configuration> <basedir>${project.build.directory}</basedir> <includes>${project.build.finalName}/WEB-INF/classes/configuration.properties</includes> <replacements> <replacement> <token>${database.name.dev}</token> <value>${database.name.test}</value> </replacement> </replacements> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>DATABASE_DEV</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <database.name.dev>USER_DEV</database.name.dev> <database.name.test>USER_DEV</database.name.test> </properties> </profile> <profile> <id>DATABASE_TEST</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <database.name.dev>USER_DEV</database.name.dev> <database.name.test>USER_TEST</database.name.test> </properties> </profile> </profiles>
</build>
打包时包含此文件不包含彼文件
profile的作用是设置环境变量
https://www.cnblogs.com/yitouniu/p/7573885.html