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
¥¥¥¥¥¥¥¥
A.pom.xml属性介绍:
project: pom的xml根元素。
parent: 声明继承。
modules: 声明聚合,该值是一个当前POM的相对目录。用户项目的聚合。
groupId: 定义当前Maven项目隶属的实际项目。
artifactId: 定义实际项目中的一个Maven项目模块,一般为实际项目名称。
version: 定义Maven项目当前版本。
groupId、artifactId、version三个属性构成项目的坐标,必须全部填写。
packaging: 坐标元素之一,可以不填,不填默认jar,表示项目构建成jar包;值为war表示可部署的web项目。
name: 名称。
description: 项目描述。
organization: 所属组织。
licenses: 许可证。
mailingLists: 邮件列表。
developers: 开发者。
contributors: 贡献者。
issueManagement: 问题追踪系统。
ciManagement: 持续集成系统。
scm: 版本控制系统。
prerequisites-->maven: 要求maven最低版本,默认值为2.0.
build-->sourceDirectory: 主源码目录。
build-->scriptSourceDirectory: 脚本源码目录。
build-->testSourceDirectory: 测试源码目录。
build-->outputDirectory: 主源码输出目录。
build-->testOutputDirectory: 测试源码输出目录。
build-->resources-->resource: 主资源目录。
build-->testResources-->testResource: 测试资源目录。
build-->finalName: 输出主构件的名称。
build-->directory: 输出目录。
build-->filters-->filter: 通过properties文件定义资源过滤属性。
build-->extensions-->extension: 扩展Maven的核心。
build-->pluginManagement: 插件管理。
build-->plugins-->plugin: 插件。
profiles-->profile: POM Profile。
distributionManagement-->repository: 发布版本部署仓库。
distributionManagement-->snapshotRepository: 快照版本部署仓库。
distributionManagement-->site: 站点部署。
repositories-->repository: 仓库。
pluginRepositories-->pluginRepository: 插件仓库。
dependencies-->dependency: 依赖管理。
properties: Maven属性。
reporting-->plugins: 报告插件。
a-->b表示a元素嵌套着b元素。
B.settings.xml文件配置。
settings: settings.xml的根元素。
localRepository: 本地仓库。
interactiveMode: Maven是否与用户交互,默认值为true。
offline: 离线模式,默认false。
pluginGroups-->pluginGroup: 插件组。
servers-->server: 下载与部署仓库的认证信息。
mirrors-->mirror: 仓库镜像。
proxies-->proxy: 代理。
profiles-->profile: Settings Profile。
activeProfiles-->activeProfile: 激活Profile。
Maven目录下的conf文件夹下的settings.xml为全局的,影响所有用户的配置。一般建议修改c:\Users\用户名\.m2\目录下的settings.xml,属于局部的,只对当前目
录下的用户有用。