使用maven-war-plugin 对Maven项目进行动态打包

在项目发布的时候,我们可能会希望保持项目代码不变的情况下,针对不同的环境获得相应的运行包(如:war)。
现在遇到的一个项目是要在发布的时候更改logback的配置。如windows环境下,log的路径为F:\\apache-tomcat-7.0.50;linux环境下为/home/server/tomcat。


代码如下:
1、logback配置:logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<contextName>quicksample</contextName>
	<property name="LOG_HOME">${log_home_value}</property>
	
	……
<configuration>

2、在maven的pom.xml中配置如下:

…
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-war-plugin</artifactId>
	<version>2.4</version>
	<configuration>
		<warName>${project.artifactId}</warName>
		<filters>
			<filter>src/main/resources/logback.xml</filter>
		</filters>
		<webResources>
			<resource>
				<filtering>true</filtering>
				<directory>src/main/resources</directory>
				<includes>
					<include>**/logback.xml</include>
				</includes>
				 <targetPath>WEB-INF/classes</targetPath>
			</resource>
		</webResources>
	</configuration>
</plugin>
…

<profiles>
	<profile>
		<id>windows</id>
		<properties>
			<log_home_value>F:\\apache-tomcat-7.0.50</log_home_value>
		</properties>
	</profile>
	<profile>
		<id>linux</id>
		<properties>
			<log_home_value>/home/server/tomcat</log_home_value>
		</properties>
	</profile>
</profiles>

3、用 mvn clean package -P windows打包

另可参考:http://nileader.blog.51cto.com/1381108/449956




转载于:https://my.oschina.net/guanzhenxing/blog/281097

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值