maven copy file文件到指定目录

本文介绍如何使用Maven和Ant任务自动复制配置文件。通过配置maven-antrun-plugin插件,在构建过程中将特定的properties文件从源位置复制到指定的目标路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚接触一个项目,里面有一个配置文件,我以为是手动添加的,项目经理说是自动产生,然后我就研究怎么产生的。。。。。

后来发现是从项目某个文件copy到本地的

<span style="font-size:18px;"><profiles>
<span style="white-space:pre">	</span><!-- The following profile is activated for the mobile voter only -->
	<profile>	
	<span style="white-space:pre">	</span><id>mobile.test.build</id>
<span style="white-space:pre">		</span><build>
<span style="white-space:pre">			</span><plugins>
				<!-- the antrun plugin is used to implement the random choice of a properties file 
					    and to copy it to the location required by the SAP Selenium2 framework -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-antrun-plugin</artifactId>
					<executions>
						<execution>
							<id>mvn-antrun-process-resources</id>
							<phase>process-resources</phase>
							<goals>
							<span style="white-space:pre">	</span><goal>run</goal>
							</goals>
						</execution>
					</executions>
					<configuration>
						<tasks>
							<!-- import the ant-contrib tasks into ANT -->
							<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
							
							<!-- copy the properties file into the temporary directory -->
							<echo>Using device: "${sap.ui5.devicename}" for testing.</echo>
							<mkdir dir="${env.USERPROFILE}/Automation/Test-Parameters/"/>
							<copy file="${basedir}/src/test/settings/${sap.ui5.devicename}.properties" tofile="${env.USERPROFILE}/Automation/Test-Parameters/Environment.properties" overwrite="true"/>
								
						</tasks> 
					</configuration>
<span style="white-space:pre">				</span></plugin>
			</plugins>				 
		</build>	
	</profile>	
</profiles></span>

是从项目的src/test/settings文件夹下,拷贝一个properties文件到C:/Users/Automation/Test-Parameters,并重命名为Envrionment.properties.

刚开始运行 mvn build 或者 mvn install都不能生成文件。后来才发现这是 maven build 的时间和antrun 插件运行时间之间的问题。

Maven build 在 maven-antrun-plugin 运行之前就执行了,所以antrun没有起作用。

运行命令:mvn -Pmobile.test.build clean install 就OK啦。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值