一,创建分环境属性配置文件
src/build-config/build-develop.properties
src/build-config/build-product.properties
src/build-config/build-test.properties
例:
build-develop.properties
#数据库配置
build.jdbc.url = jdbc:oracle:thin:@ip:port:database
build.jdbc.username = name
build.jdbc.password = pwd
build.jdbc.driverClassName = oracle.jdbc.driver.OracleDriver
二,修改配置文件为可分环境替换
例:
jdbc.properties
#数据库地址
jdbc.url = @[email protected]
#数据库用户名
jdbc.username = @[email protected]
#数据库密码
jdbc.password = @[email protected]
#数据库驱动
jdbc.driverClassName = @[email protected]
三,pom重新定义分环境打包需使用的占位符
<properties>
<resource.delimiter>@</resource.delimiter>
</properties>
四,pom分环境配置
<!-- 分环境配置 -->
<profiles>
<profile>
<id>develop</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<project.env>develop</project.env>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<project.env>product</project.env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<project.env>test</project.env>
</properties>
</profile>
</profiles>
<build>
<!-- 分环境过滤器 -->
<filters>
<filter>build-config/build-${project.env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<!-- 是否分环境过滤 -->
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<!-- 是否分环境过滤 -->
<filtering>true</filtering>
</resource>
</resources>
</build>
原文地址:http://blog.51cto.com/jtech/2153428
时间: 2024-10-12 00:45:53