Maven pom.xml加载不同properties配置
2015-09-26 16:44
405 查看
1.pom.xml
===========================
<!-- 不同的打包环境配置: test=开发/测试测试环境, product=生产环境; 命令行方式: mvn clean install -Dmaven.test.skip=true -Ptest 或 -Pproduct-->
<profiles>
<!-- 开发/测试环境,默认激活 -->
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault><!--默认启用的是dev环境配置-->
</activation>
</profile>
<!-- 预发布环境 -->
<profile>
<id>preproduction</id>
<properties>
<env>preproduction</env>
</properties>
</profile>
<!-- 生产环境 -->
<profile>
<id>production</id>
<properties>
<env>production</env>
</properties>
</profile>
</profiles>
<build>
<filters> <!-- 指定使用的 filter -->
<filter>src/main/filters/filter-${env}-env.properties</filter>
</filters>
<resources>
<resource> <!-- 配置需要被替换的资源文件路径, db.properties 应该在 src/main/resource 目录下 -->
<directory>src/main/resources</directory>
<filtering>true</filtering> <!-- 是否使用过滤器 -->
</resource>
</resources>
</build>
2.src/main/filters/下不同环境的配置文件
src/main/filters/filter-preproduction-env.properties
src/main/filters/filter-production-env.properties
src/main/filters/filter-test-env.properties
======filter-test-env.properties 举例
jdbc.url=jdbc:mysql://192.168.120.220:3306/testdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
jdbc.username=testuser
jdbc.password=123456
3.src/main/resources下要应用处理的文件
src/main/resources/conf/db.properties
======db.properties
jdbc.datasource=com.mchange.v2.c3p0.ComboPooledDataSource
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
jdbc.minPoolSize=10
jdbc.maxPoolSize=50
jdbc.autoCommit=false
===========================
<!-- 不同的打包环境配置: test=开发/测试测试环境, product=生产环境; 命令行方式: mvn clean install -Dmaven.test.skip=true -Ptest 或 -Pproduct-->
<profiles>
<!-- 开发/测试环境,默认激活 -->
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault><!--默认启用的是dev环境配置-->
</activation>
</profile>
<!-- 预发布环境 -->
<profile>
<id>preproduction</id>
<properties>
<env>preproduction</env>
</properties>
</profile>
<!-- 生产环境 -->
<profile>
<id>production</id>
<properties>
<env>production</env>
</properties>
</profile>
</profiles>
<build>
<filters> <!-- 指定使用的 filter -->
<filter>src/main/filters/filter-${env}-env.properties</filter>
</filters>
<resources>
<resource> <!-- 配置需要被替换的资源文件路径, db.properties 应该在 src/main/resource 目录下 -->
<directory>src/main/resources</directory>
<filtering>true</filtering> <!-- 是否使用过滤器 -->
</resource>
</resources>
</build>
2.src/main/filters/下不同环境的配置文件
src/main/filters/filter-preproduction-env.properties
src/main/filters/filter-production-env.properties
src/main/filters/filter-test-env.properties
======filter-test-env.properties 举例
jdbc.url=jdbc:mysql://192.168.120.220:3306/testdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
jdbc.username=testuser
jdbc.password=123456
3.src/main/resources下要应用处理的文件
src/main/resources/conf/db.properties
======db.properties
jdbc.datasource=com.mchange.v2.c3p0.ComboPooledDataSource
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
jdbc.minPoolSize=10
jdbc.maxPoolSize=50
jdbc.autoCommit=false
相关文章推荐
- 1.4 CentOS7 配置AMP环境之安装准备
- 单服务器发布多网站的问题
- linux上搭建完整go语言vim开发环境
- apache集成php5.6方法分享
- 二:shell之bash变量
- centos LAMP搭建
- linux中nginx
- 1.3 CentOS7设置FTP
- Linux apt-get
- Linux(9.21-9.27)学习笔记
- Linux(9.21-9.27)学习笔记
- 磁盘iops 测试 fio 及报错解释
- opengl 画正N边形
- GNU Linux mount挂载的常用三种方法
- 基于tomcat运行HTML5 WebSocket echo例子
- Linux 中 10 个有用的命令行补全例子
- Linux 中 10 个有用的命令行补全例子
- Tomcat启动提示
- tomcat虚拟路径发布网站
- 1.2 Xshell连接CentOS