maven pom进阶教程 - 资源文件拷贝插件maven-resources-plugin

官方文档http://maven.apache.org/plugins/maven-resources-plugin/index.html
它最常用的两个goal:
resources:resources 这是process-resources阶段的默认goal, 在不配置任何参数的情况下,将默认使用build.resources中的目录作为源路径,将build.outputDirectory作为目标路径(实际上是这目录下的classes).
resources:copy-resources 需要明确的指定源路径和目标路径.
示例如下

<build>
	<outputDirectory>${project.basedir}/target</outputDirectory> <!-- 废代码,默认值就是个 -->
	<resources>
		<resource>
			<directory>${project.basedir}/src/main/resources</directory> <!-- 废代码, 默认值 -->
		</resource>
	</resources>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-resources-plugin</artifactId>
			<version>3.0.2</version>
			<executions>
				<execution> <!--本示例显式地配置了process-resource阶段的插件配置-->
					<id>default-resources</id> <!-- default-resources是process-resource阶段绑定的id,因此本配置将取代默认的配置 -->
					<phase>validate</phase><!-- 默认操作原本是在process-resource阶段执行的,本示例将其更改到了validate阶段 -->
					<goals>
						<goal>resources</goal><!--废代码,default-resources的goal就是resource,如果这里的值更改为copy-resources, 则需要显示配置resource和outputDirectory, 并且导致资源拷贝操作被执行两次 -->
					</goals>
					<configuration>  
						<!-- 如果不配置,则使用build.resources作为源,build.outputDirectory作为目标, 如果明确进行了配置,build.resources将被忽略 -->  
						<!--  </br>
						<outputDirectory>${project.basedir}/target/classes</outputDirectory>    
						<resources>  
							<resource>  
								<directory>src/main/resources</directory>  
								<filtering>false</filtering>  
							</resource>  
						</resources>  
						<skip>false</skip>  如果配置为true,则本操作不被执行  
						 -->
					</configuration>
				</execution>
				<execution>
					<id>copy2</id> <!--自定义的id,随便写 -->
					<phase>compile</phase><!--在compile阶段执行-->
					<goals>
						<goal>copy-resources</goal><!--这个goal需要明确的配置-->
					</goals>
					<configuration>
						<outputDirectory>${project.basedir}/target/conf3</outputDirectory>
						<resources>
							<resource>
								<directory>src/main/resources3</directory>
								<filtering>true</filtering> <!--开启资源文件插值操作-->
								<includes><!--包含directory下的所有的properties, 包括子目录-->
									<include>**/*.properties</include>
								</includes>
							</resource>
						</resources>
					</configuration>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

filter,见maven pom进阶教程 - properties、filter

转载于:https://my.oschina.net/u/2343729/blog/830954

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值