我想在 ant 构建文件中定义一个变量列表,以便在我的任务中使用这个列表的 for 循环。我该怎么做?
p.s.: 应该是这样的:
<varlist name="mylist"> <!-- Actually, there is no such tag in Ant -->
<item>someThing</item>
<item>anotherThing</item>
</varlist>
...
<for param="item" list="${mylist}">
<sequential>
<echo>@{item}</echo>
</sequential>
</for>
最佳答案
<!-- "For" task is supported by Ant-Contrib Tasks
http://ant-contrib.sourceforge.net/tasks/tasks/index.html -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<property name="someThing" value="Hello"/>
<property name="anotherThing" value="World!"/>
<target name="loop">
<for param="item" list="${someThing},${anotherThing}">
<sequential>
<echo>@{item}</echo>
</sequential>
</for>
</target>
关于java - 在 ant 中定义一个列表或一组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10030190/