Jakarta ee Maven 3:当文件不存在时,如何将文件复制到测试目录
我想在maven阶段测试期间将一个文件从src目录复制到test/resource目录,当且仅当文件不存在于test/resource目录中时。有人知道我们如何实现这一点吗?提前感谢使用来实现这一点。在pom.xml中,使用Jakarta ee Maven 3:当文件不存在时,如何将文件复制到测试目录,jakarta-ee,ant,maven-3,maven-plugin,Jakarta Ee,Ant,Maven 3,Maven Plugin,我想在maven阶段测试期间将一个文件从src目录复制到test/resource目录,当且仅当文件不存在于test/resource目录中时。有人知道我们如何实现这一点吗?提前感谢使用来实现这一点。在pom.xml中,使用 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifact
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<if>
<available file="/path/to/your/file "/>
<then>
<!-- Do something with it -->
<copy file="/your/file" tofile="/some/destination/path" />
</then>
</if>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven antrun插件
1.6
测验
跑
使用来完成此操作。在pom.xml中,使用
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<if>
<available file="/path/to/your/file "/>
<then>
<!-- Do something with it -->
<copy file="/your/file" tofile="/some/destination/path" />
</then>
</if>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven antrun插件
1.6
测验
跑
您可以使用runIf
在何处检查文件是否存在。您可以使用runIf
在何处检查文件是否存在。以下是@Saif Asif的答案的更新版本,适用于我的Maven3:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.dependency.classpath" />
<if>
<available file="/path/to/your/file "/>
<then>
<!-- Do something with it -->
<copy file="/your/file" tofile="/some/destination/path" />
</then>
</if>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
org.apache.maven.plugins
用于“向插件添加依赖项”解决方案
本例中值得注意的变化是:
- 将插件更新为1.8版(最新版本为本文撰写之时)
- 已更新taskdef,使classpathref符合
- 根据将taskdef classpathref更改为与maven3一起使用
以下是@Saif Asif答案的更新版本,它在Maven3上对我有用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.dependency.classpath" />
<if>
<available file="/path/to/your/file "/>
<then>
<!-- Do something with it -->
<copy file="/your/file" tofile="/some/destination/path" />
</then>
</if>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
org.apache.maven.plugins
用于“向插件添加依赖项”解决方案
本例中值得注意的变化是:
- 将插件更新为1.8版(最新版本为本文撰写之时)
- 已更新taskdef,使classpathref符合
- 根据将taskdef classpathref更改为与maven3一起使用
感谢@Saif的回复。当我尝试你的代码时,我遇到了以下异常情况。。[错误]无法执行目标org.apache.maven.plugins:maven antrun插件:1.6:在项目******上运行(默认):发生Ant BuildException:问题:无法创建任务或类型如果[错误]原因:名称未定义。[错误]操作:检查拼写。[错误]操作:检查是否已声明任何自定义任务/类型。[错误]操作:检查所有/声明是否已执行。是否定义了名为antcontrib.properties的任务?如果没有,请删除代码中提到的线条,。这是我在pom.xml中拥有的唯一一个文件。我已经厌倦了从pom中删除此项。不构建执行良好。但是复制不起作用。下面是我用于文件复制的代码,其工作良好。但是,如果它们是src中的某个技术,则覆盖目标文件。这不会发生。你的意思是说它不适用于if-then语句?是的。它好像没有执行Condition语句。感谢@Saif的响应。当我尝试你的代码时,我得到了以下异常。。[错误]无法执行目标org.apache.maven.plugins:maven antrun插件:1.6:在项目******上运行(默认):发生Ant BuildException:问题:无法创建任务或类型如果[错误]原因:名称未定义。[错误]操作:检查拼写。[错误]操作:检查是否已声明任何自定义任务/类型。[错误]操作:检查所有/声明是否已执行。是否定义了名为antcontrib.properties的任务?如果没有,请删除代码中提到的线条,。这是我在pom.xml中拥有的唯一一个文件。我已经厌倦了从pom中删除此项。不构建执行良好。但是复制不起作用。下面是我用于文件复制的代码,其工作良好。但是,如果它们是src中的某个技术,则覆盖目标文件。这不会发生。你的意思是说它不适用于if-then语句?是的。它不适用于Condition语句。谢谢@UR6LAD,这个插件做得很好。文件副本按预期工作。我们的客户对这个插件不满意…:(.他们说该插件似乎向maven引入了一种过程性的“脚本”,我觉得这与maven与ant的区别正好相反。我使用的插件的核心逻辑如下。请让我知道他们是否还有其他选择。{{!新文件(“src/test/resources/systemConfig.properties”).exists()}}src/test/resources development/env/systemConfig.properties。提前感谢。感谢@UR6LAD,这个插件做得很好。文件副本按预期工作。我们的客户对这个插件不满意…:(.他们说这个插件似乎引入了一种过程性的“脚本”对于maven,我觉得这与maven与ant的区别正好相反。我使用的插件的核心逻辑如下。请让我知道他们是否还有其他选择。{{!新文件(“src/test/resources/systemConfig.properties”).exists()}}src/test/resources development/env/systemConfig.properties。提前感谢。