maven pom.xml加载不同properties配置[转]
可以参考http://www.openwebx.org/docs/autoconfig.html
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
-----------------------------------
自定义配置属性:
Custom properties in the POM
User defined properties in the pom.xml.
<project>
...
<properties>
<my.filter.value>hello</my.filter.value>
</properties>
...
</project>
- ${my.filter.value } will result in hello if you inserted the above XML fragment in your pom.xml
再比如:在pom.xml中properties自定义如下:
- <properties>
- <springframework_version>3.1.0.RELEASE</springframework_version>
- <maven.bbs.appConfig>itConfig.xml</maven.bbs.appConfig>
- </properties>
在web容器加载的时候,假如spring监听的配置文件是:applicationContext.xml,那么applicationContext.xml文件内容可以这样写来引入maven的properties属性值:
<import resource="${maven.bbs.appConfig}"/>
maven编译过后,targer项目里面的applicationContext.xml里面相应的引入就会变成
<import resource="itConfig.xml"/>
<build>
<!-- autoconfig with antx.properties -->
<filters>
<filter>${filterFile}</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build> <profiles>
<profile>
<id>dev</id>
<properties>
<filterFile>antx.properties</filterFile>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles> 现在发现有两种可以实现配置
一种是使用filter
第二种是使用
autoconfig-maven-plugin 来产生autoconfig
maven pom.xml加载不同properties配置[转]的更多相关文章
- maven pom.xml加载不同properties配置
1.pom.xml =========================== <!-- 不同的打包环境配置: test=开发/测试测试环境, product=生产环境; 命令行方式: mvn c ...
- maven项目pom.xml加载本地jar,自定义jar
将jar放到resource目录下面: pom添加配置 <!-- 加载IK自定义 依赖--> <dependency> <groupId>com.ik.up< ...
- 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样
[参考]:maven pom.xml加载不同properties配置[转] 首先 看看效果: 点开我们项目中的Maven projects 后,会发现右侧 我们profile有个可勾选选项.默认勾选l ...
- (转)Maven pom.xml 配置详解
背景:maven一直感觉既熟悉又陌生,归根结底还是自己不太熟. 1 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者 ...
- Maven(四-2) Maven pom.xml 配置详解
转载于:http://niuzhenxin.iteye.com/blog/2042102 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述 ...
- Maven pom.xml 全配置(二)不常用配置
Maven pom.xml 全配置(二)不常用配置 这里贴出Maven pom.xml文件中使用率较少的配置参数,如果此篇文档中没有找到你想要的参数,移步Maven pom.xml 全配置(一)常用配 ...
- Maven pom.xml 全配置(一)常用配置
Maven pom.xml 全配置(一)常用配置 这里贴出一个Maven中出现频率较高的配置参数注释,方便理解项目中Maven的配置具体的作用.如果在此博文中没有找到你想看到的参数,可以移步Maven ...
- web工程中web.xml元素加载顺序以及配置实例
简介 web.xml是web工程的配置文件,容器加载web工程时,会首先从WEB-INF中查询web.xml,并加载其中的配置信息,可以将web.xml认为是web工程的入口. web.xml中包含有 ...
- myeclipse maven pom.xml 配置错误
http://www.oschina.net/question/2265006_219341#tags_nav maven pom.xml 配置文件错误 腾讯云消息队列CMQ架构解析> ...
随机推荐
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- 【hdu 5918】Sequence I(KMP)
给定两个数字序列,求a序列中每隔p个构成的p+1个序列中共能匹配多少个b序列. 例如1 1 2 2 3 3 每隔1个的序列有两个1 2 3 kmp,匹配时每次主串往前p个,枚举1到p为起点. 题目 # ...
- 【CodeForces 699D】Fix a Tree
dfs找出联通块个数cnt,当形成环时,令指向已访问过节点的节点变成指向-1,即做一个标记.把它作为该联通图的根. 把所有联通的图变成一颗树,如果存在指向自己的点,那么它所在的联通块就是一个树(n-1 ...
- String,Date,XMLGregorianCalendar的转换
常见标准的写法"yyyy-MM-dd HH:mm:ss",区分大小写,时间是24小时制,24小时制转换成12小时制只需将HH改成hh. String to Date: String ...
- 快速查找无序数组中的第K大数?
1.题目分析: 查找无序数组中的第K大数,直观感觉便是先排好序再找到下标为K-1的元素,时间复杂度O(NlgN).在此,我们想探索是否存在时间复杂度 < O(NlgN),而且近似等于O(N)的高 ...
- bzoj2938: [Poi2000]病毒
建AC自动机,把所有病毒的节点都删掉,dfs判有没有环,有环就找得到. #include <iostream> #include <cstdio> #include <c ...
- libusb-win32简介~
libusb-win32简介 libusb-win32 is a port of the USB library libusb (http://sf.net/projects/libusb/) to ...
- gvim e303 无法打开 “[未命名]“的交换文件,恢复将不可能
今天vim出现:“gvim e303 无法打开 “[未命名]“的交换文件,恢复将不可能” 解决办法: 修改你的.vimrc,增加下面的一行: set directory=.,$TEMP "默 ...
- php发送http请求方法实例及详解
http请求有get,post. php发送http请求有三种方式[我所知道的有三种,有其他的告诉我]. file_get_contents();详情见:http://www.whosmall.com ...
- Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径 Java编程 spring的配置文件applicationContext.xml的默 ...