【问题标题】:<param> under <foreach> doesn't support nested fileset element<foreach> 下的 <param> 不支持嵌套文件集元素
【发布时间】:2015-12-04 15:40:24
【问题描述】:

我正在尝试执行一项应该遍历一组文件的任务。为此,我正在使用 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>

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

构建失败

C:\Users\rmrd001\git\xslt-framework\implementation\xml\ant\text-odt-build.xml:13:参数不支持嵌套的“文件集”元素。

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

【问题讨论】:

  • 你考虑过拼写正确吗?
  • @EJP 昨天英语不是我的自然语言。我完全依赖编辑器拼写检查。

标签: java ant ant-contrib


【解决方案1】:

您链接到的&lt;foreach&gt; 示例来自Apache Axis 1.x Ant tasks 项目。这是一个不同于 &lt;foreach&gt;Ant-Contrib 项目。

正如 manouti 所说,Ant-Contrib &lt;foreach&gt; 不支持嵌套的 param 元素。相反,&lt;fileset&gt;id 可以传递给&lt;target&gt;&lt;target&gt; 可以引用id

或者,您可以使用 Ant-Contrib 的 &lt;for&gt; task(不是“&lt;foreach&gt;”),它可以调用 &lt;macrodef&gt;...

<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>

【讨论】:

    【解决方案2】:

    请参阅http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html 了解如何使用foreachparam 必须是 属性 而不是嵌套元素:

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

    【讨论】:

      猜你喜欢
      • 2016-12-16
      • 2015-10-21
      • 1970-01-01
      • 2015-10-27
      • 2023-01-14
      • 1970-01-01
      • 2018-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多