[英]<param> under <foreach> doesn't support nested fileset element
I am trying to perform a task that is supposed to iterate over a set of files. 我正在尝试执行应该迭代一组文件的任务。 For that I am using the foreach
task from ant-contrib-0.3.jar . 为此,我使用了ant-contrib-0.3.jar中的foreach
任务。 The problem is that I am trying to pass (as param) to the target not the file path, but the file directory path. 问题是我试图将(作为参数)传递给目标,而不是文件路径,而是文件目录路径。
Here is the project: 这是项目:
<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>
Running the script I am getting the following message: 运行脚本,我收到以下消息:
BUILD FAILED 建立失败
C:\\Users\\rmrd001\\git\\xslt-framework\\implementation\\xml\\ant\\text-odt-build.xml:13: param doesn't support the nested "fileset" element. C:\\ Users \\ rmrd001 \\ git \\ xslt-framework \\ implementation \\ xml \\ ant \\ text-odt-build.xml:13:param不支持嵌套的“ fileset”元素。
I can read in several places on the internet (such as axis.apache.org ) that param
can have a nested fileset
element. 我可以在Internet上的多个位置(例如axis.apache.org )上阅读到, param
可以具有嵌套的fileset
元素。
See http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html for how to use foreach
. 有关如何使用foreach
请参见http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html 。 The param
must be an attribute not a nested element: param
必须是属性,而不是嵌套元素:
<target name="copy-all-unzipped">
<foreach target="copy-unzipped" param="file-path">
<fileset dir="${path.unzipped}">
<include name="**/content.xml"/>
</fileset>
</foreach>
</target>
The example of <foreach>
you link to is from the Apache Axis 1.x Ant tasks project. 链接到的<foreach>
示例来自Apache Axis 1.x Ant任务项目。 This is a different <foreach>
than the one from the Ant-Contrib project. 这与Ant-Contrib项目中的<foreach>
不同。
As manouti says, the Ant-Contrib <foreach>
doesn't support nested param
elements. 正如manouti所说,Ant-Contrib <foreach>
不支持嵌套的param
元素。 Instead, the id
of a <fileset>
can be passed to the <target>
and the <target>
can reference the id
. 相反,可以将<fileset>
的id
传递给<target>
,而<target>
可以引用该id
。
Or, you can use Ant-Contrib's <for>
task (not " <foreach>
") which can call a <macrodef>
... 或者,您可以使用Ant-Contrib的<for>
任务 (不是“ <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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.