多环境配置文件选择,maven打包配置

使用 run as --> maven build  在Goals: 输入 clean package -Ptest 打包时项目自动把 conf/test 目录下config.properties文件拷贝到server.war包中 WEB-INF/classes 目录 下。

pom.xml 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.springframework.samples.service.service</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging> 
  	
	<dependencies>
	
		
		
	</dependencies>

	<profiles>
		<profile>
			<!-- 本地开发环境 -->
			<id>dev</id>
			<properties>
				<package.environment>conf/dev</package.environment>
			</properties>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
		</profile>
		<profile>
			<!-- 测试环境 -->
			<id>test</id>
			<properties>
				<package.environment>conf/test</package.environment>
			</properties>
		</profile>
		<profile>
			<!-- 生产环境 -->
			<id>prod</id>
			<properties>
				<package.environment>conf/prod</package.environment>
			</properties>
		</profile>
	</profiles>
	<build>
		<finalName>server</finalName>
		<sourceDirectory>src</sourceDirectory>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1.1</version>
				<configuration>
<!-- 					<webXml>src\main\webapp\WEB-INF\web.xml</webXml> -->
<!-- 					<warSourceDirectory>webapp</warSourceDirectory> -->
					<archive>
						<addMavenDescriptor>false</addMavenDescriptor>
					</archive>
					<warName>server</warName>
					<webResources>
						<resource>
							<directory>src/main/resources/${package.environment}</directory>
							<targetPath>WEB-INF/classes</targetPath>
							<filtering>true</filtering>
						</resource>
					</webResources>
				</configuration>
			</plugin>
		</plugins>
		<resources>
			<resource>
				<directory>src</directory>
				<filtering>true</filtering>
				<includes>
					<include>**/*.properties</include>
					<!-- <include>**/*.xml</include> -->
				</includes>
			</resource>
		</resources>
	</build>
</project> 
	
	
		
</project>

 

 

转载于:https://my.oschina.net/ludd79806329/blog/784890

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值