用户工具

站点工具


分享:技术:maven:profile的介绍和使用

这是本文档旧的修订版!


profile的介绍和使用

profile的介绍

同一个项目使用同一个pom.xml来构建不同的环境时候,比如:本地环境(local)日志输出目录:D:/logs/record/record.log,而测试环境(test)日志输出目录:/home/gxx/logs/record/record.log;又比如:本地环境(local)使用数据源1,而测试环境(test)使用数据源2。

profile的使用

<!-- 使用 mvn clean install -P XXX 激活profile -->
<profiles>
	<profile>
		<id>local</id>
		<activation>
			<activeByDefault>true</activeByDefault>
		</activation>
		<properties>
			<deploy.environment.include>local</deploy.environment.include>
			<deploy.environment.exclude>test</deploy.environment.exclude>
			<log4j.dir>D:/logs/record/record.log</log4j.dir>
		</properties>
	</profile>
	<profile>
		<id>test</id>
		<properties>
			<deploy.environment.include>test</deploy.environment.include>
			<deploy.environment.exclude>local</deploy.environment.exclude>
			<log4j.dir>/home/gxx/logs/record/record.log</log4j.dir>
		</properties>
	</profile>
</profiles>

其中两个profile表示两个环境,local为本地环境,test为测试环境,<activeByDefault>true</activeByDefault>表示默认环境,<properties>内的值为相应环境下配置的值,不管在properties或者xml或者pom.xml中都可以取出这些值,取的方法是:${属性值},比如${deploy.environment.exclude}和${log4j.dir}

分享/技术/maven/profile的介绍和使用.1436778334.txt.gz · 最后更改: 2015/07/13 17:05 由 gxx