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