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架构解析> ...
随机推荐
- <UL>中<li>标签前编号图片的简单调用
<style type="text/css"> ul li{ list-style-type:none} .men ul{ background:url(http:// ...
- 100726A
迭代深搜,从最深的地方搜,然后一个数被搜过了,标记用过,以后不再访问 #include<iostream> #include<cstring> #include<map& ...
- sql insert into select语句写法-将查询结果直接插入到表中
insert into month_gpcj_info(idStr,zszrmygpsl,xyzrmygpsl,mycje,mycjl,month_date,dataCompiledDate) sel ...
- Timer和DPC
一般两种方法使用/设置定时器,一种是使用I/O定时器例程,一种是使用DPC例程.1.定时器的实现1)使用I/O定时器例程NTSTATUSIoInitializeTimer(IN PDEVICE_OBJ ...
- 让Bootstrap 3兼容IE8浏览器
最近在研究Bootstrap(官方,Github)这个优秀的前端框架,Bootstrap最开始是Twitter团队内部的一个前端框架,所谓前端框架就是一个CSS/HTML框架,框架里面有下拉菜单.按钮 ...
- Handler的postDelayed方法
这是一种可以创建多线程消息的函数 使用方法:1,首先创建一个Handler对象 Handler handler=new Handler(); 2,然后创建一个Runnable对象 Runnable r ...
- Unity 移动端触摸屏操作
Unity 触屏操作 当将Unity游戏运行到IOS或Android设备上时,桌面系统的鼠标左键可以自动变为手机屏幕上的触屏操作,但如多点触屏等操作却是无法利用鼠标操作进行的.Unity的Input类 ...
- JS实现打印功能
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ t ...
- SQL Server修改代理作业的下次运行时间
有这个现象,如果我把服务器时间调快2天运行作业,那么会发现作业的下次运行时间会变成两天+1的时间,即使是把服务器时间调正常后,这个下次运行时间也是无法调回来的 那么,要修改会正常的下次作业时间,可以这 ...
- Writing a simple Lexer in PHP/C++/Java
catalog . Comparison of parser generators . Writing a simple lexer in PHP . phc . JLexPHP: A PHP Lex ...