利用maven的resources、filter和profile实现不同环境使用不同配置文件
https://blog.csdn.net/zhuchunyan_aijia/article/details/50464720
pom.xml:
<project> <build> <fileName>app</fileName> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> <resource> <directory>src/main/filters/META-INF/${env.name}/common</directory> <filtering>true</filtering> <targetPath>META-INF/common</targetPath> </resource> </resources> </build> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <maven.val>abc</maven.val> <env.name>dev</env.name> </properties> </profile> <profile> <id>sit</id> <properties> <maven.val>def</maven.val> <evn.name>sit</env.name> </properties> </profile> </profiles> </project>
directory:
src/main/java src/main/resources src/main/filters/META-INF/dev/common/distribute-session.xml src/main/filters/META-INF/sit/common/distribute-session.xml
maven command:
mvn clean install -DskipTests -Pdev mvn clean install -DskipTests -Psit
===============================
不同的版本需要的配置文件不同:
<project> ......
<build> <finalName>tmcweb</finalName> <!--<resources>--> 注意这块不用了,使用profile自己的; <!--<resource>--> <!--<directory>src/main/resources</directory>--> <!--<filtering>true</filtering>--> <!--</resource>--> <!--</resources>--> <plugins> <plugin> 这里是一个插曲 <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin> </plugins> </build> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <env>dev</env> </properties> <build> <resources> <resource> 在profile里面引入resource才可以exclude <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>META-INF/common/x-prod.xml</exclude> </excludes> </resource> </resources> </build> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>META-INF/common/x-dev.xml</exclude> </excludes> </resource> </resources> </build> </profile> </profiles> </project>