java - 在 ant 中定义一个列表或一组变量

标签 java list ant for-loop

我想在 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/

相关文章:

java - 使用 Spring restTemplate 遵循 302 重定向?

java.lang.VerifyError : main() threw exception :Incompatible argument to function

c# - 用一定数量的元素初始化 List<>

java - Ant 找不到 javac,在 Ubuntu 上不会设置 JAVA_HOME

java - 老板。如何确定一段时间内的并发用户数?

java - 字符串中的数字总和无法正常工作

python - 对于列表的每个成员,将其写入单独的文件 python

c# - 从值为 List<string> 的字符串中获取键

command-line - 我如何有选择地要求 Ant 的命令行参数?

ant - Ivy , Ant , Jenkins - <ivy :cleancache> on Jenkins builds? 是个好主意