gpt4 book ai didi

java - Maven 安特伦 : how to iterate over files?

转载 作者:行者123 更新时间:2023-11-29 03:15:55 25 4
gpt4 key购买 nike

我已经在 https://github.com/jjYBdx4IL/example-maven-project-setups/blob/master/antrun-foreach/pom.xml 设置了一个示例:

        <plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-test-resources</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<foreach target="unzipLibs" param="fileName">
<path>
<fileset dir="${basedir}" casesensitive="yes">
<include name="*.xml"/>
</fileset>
</path>
</foreach>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<!-- <exclusions>
<exclusion>
<artifactId>ant</artifactId>
<groupId>ant</groupId>
</exclusion>
</exclusions>-->
</dependency>
</dependencies>
<configuration>
<target name="unzipLibs">
<echo message="${fileName}" />
</target>
</configuration>
</plugin>

然而,无论我怎么尝试,它都不起作用:

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project antrun-foreach: Error executing ant tasks: org.apache.tools.ant.util.FileUtils.getFileUtils()Lorg/apache/tools/ant/util/FileUtils; -> [Help 1]

或者,使用 Ant 排除:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project antrun-foreach: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] /home/travis/build/jjYBdx4IL/example-maven-project-setups/antrun-foreach/pom.xml:5: Unexpected element "{http://maven.apache.org/POM/4.0.0}project" {antlib:org.apache.tools.ant}project
[ERROR] around Ant part ...<foreach param="fileName" target="unzipLibs">... @ 5:48 in /home/travis/build/jjYBdx4IL/example-maven-project-setups/antrun-foreach/target/antrun/build-main.xml

Complete build log .

将 ant 任务移动到外部文件中没有帮助。

更新:问题似乎是 maven-antrun-plugin 不支持定义多个 antrun 目标:https://jira.codehaus.org/browse/MANTRUN-86 .

副本:Calling foreach in maven-antrun-plugin .

最佳答案

通过将目标定义移动到单独的 ant xml 构建文件中解决。

        <plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-test-resources</phase>
<configuration>
<target>
<!-- maven does not support defining more than one target... -->
<!-- https://jira.codehaus.org/browse/MANTRUN-86 -->
<ant antfile="${basedir}/unzip.xml" />
</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>
<artifactId>ant</artifactId>
<groupId>ant</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<configuration>
</configuration>
</plugin>

解压.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main" >
<target name="main">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<foreach param="fileName" target="unzipLibs">
<path>
<fileset dir="/home/mark/mysvn/devel/java/misc/maven/antrun-foreach" casesensitive="yes">
<include name="*.xml"/>
</fileset>
</path>
</foreach>
</target>
<target name="unzipLibs">
<echo message="${fileName}"/>
</target>
</project>

关于java - Maven 安特伦 : how to iterate over files?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26694307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com