java - <foreach> 下的 <param> 不支持嵌套文件集元素

标签 java ant ant-contrib

我正在尝试执行一项应该迭代一组文件的任务。为此,我使用 ant-contrib-0.3.jar 中的 foreach 任务。问题是我试图将(作为参数)传递给目标而不是文件路径,而是文件目录路径。

这是该项目:

<project basedir="../../../" name="do-report" default="copy-all-unzipped">
    <xmlproperty keeproot="false" file="implementation/xml/ant/text-odt-properties.xml"/>
    <!--    -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${path.infrastructure}/apache-ant-1.9.6/lib/ant-contrib-0.3.jar"/>
        </classpath>
    </taskdef>
    <!--    -->
    <target name="copy-all-unzipped">
        <foreach target="copy-unzipped">
            <param name="file-path">
                <fileset dir="${path.unzipped}">
                    <include name="**/content.xml"/>
                </fileset>
            </param>
        </foreach>
    </target>
    <!--    -->
    <target name="copy-unzipped">
        <echo>${file-path}</echo>
    </target>
</project>

运行脚本我收到以下消息:

BUILD FAILED

C:\Users\rmrd001\git\xslt-framework\implementation\xml\ant\text-odt-build.xml:13: param doesn't support the nested "fileset" element.

我可以在互联网上的多个地方(例如 axis.apache.org )看到 param 可以具有嵌套的 fileset 元素。

最佳答案

<foreach> 的示例您链接到的是 Apache Axis 1.x Ant tasks项目。这是一个不同的<foreach>Ant-Contrib 中的那个项目。

正如 manouti 所说,Ant-Contrib <foreach>不支持嵌套 param元素。相反,id<fileset>可以传给<target><target>可以引用id .

或者,您可以使用 Ant-Contrib 的 <for> task (不是“<foreach> ”)可以调用 <macrodef> ...

<target name="copy-all-unzipped">
    <for param="file">
        <path>
            <fileset dir="${path.unzipped}">
                <include name="**/content.xml"/>
            </fileset>
        </path>
        <sequential>
            <copy-unzipped file-path="@{file}"/>
        </sequential>
    </for>
</target>

<macrodef name="copy-unzipped">
    <attribute name="file-path"/>
    <sequential>
        <echo>@{file-path}</echo>
    </sequential>
</macrodef>

关于java - <foreach> 下的 <param> 不支持嵌套文件集元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34091966/

相关文章:

java - 可以从命令行在 Eclipse 中启动 Java EE 服务器吗?

gradle - ..\build\classes 文件夹中的 Netbeans 8.0.2 impl-dif.xml 文件错误 "Unable to delete file..."

java - 遍历文件集时出现问题

ant - 在 ant 脚本中使用最近的 Rhino

java - 通过 maven-antrun-plugin 使用 antcontrib <if> 任务

ant - 如何使用 ANT 脚本将文件复制到 zip 文件中?

Java Sockets 多次连接尝试 - 无法向所有客户端发送数据

java - Java中的二维数组使用字符(包括特殊字符)作为索引

java - 独立 java 与 tomcat 服务器的日期差异

java - 请帮助我使用 Java 中的 JFrame 和 BorderLayout