我的构建脚本中有这样的构造:
<for list="item1,item2,item3,item4" param="theparam">
<!-- some stuff to do -->
</for>
执行脚本时,我得到:
For 任务中使用的类型类 net.sf.antcontrib.logic.ForTask 无效,它没有公共(public)迭代器方法
我正在使用 ant-contrib 1.0b3。我在这里缺少什么?
最佳答案
无法重现您的问题。您使用什么版本的 ANT?
示例
$ ant -version
Apache Ant(TM) version 1.9.0 compiled on March 5 2013
$ ant
Buildfile: /home/mark/build.xml
run:
[echo] param: one
[echo] param: two
[echo] param: three
[echo] param: four
BUILD SUCCESSFUL
Total time: 0 seconds
build.xml
<project name="ant-contrib-tasks" default="run">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<target name="bootstrap">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ant-contrib.jar" src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
</target>
<target name="run">
<for param="theparam" list="one,two,three,four">
<sequential>
<echo message="param: @{theparam}"/>
</sequential>
</for>
</target>
</project>
注释:
- 特殊的“bootstrap”目标安装 ant-contrib 依赖项。
关于for-loop - ant-contrib 中带有 "for"参数的 "list"任务不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19356656/