如何在Ant中使用类似数组或列表的内容?

Piy*_*ush 6 ant ant-contrib

我在Ant脚本中有一个字符串列表(例如"piyush,kumar"),我希望将其分配piyush给var1 <var name="var1" value="piyush"/>kumarvar2之类的<var name="var2" value="kumar"/>.

到目前为止,我正在使用如下的构建文件:

<?xml version="1.0"?>
<project name="cutter" default="cutter">
<target name="cutter">
<for list="piyush,kumar" param="letter">
  <sequential>
    <echo>var1 @{letter}</echo>
  </sequential>
</for>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)

我不知道如何推进这个 - 任何建议?

mar*_*ton 9

这是一个使用ant-contrib 变量math任务的例子:

<var name="index" value="1"/>
<for list="piyush,kumar" param="letter">
  <sequential>
    <property name="var${index}" value="@{letter}" />
    <math result="index" operand1="${index}" operation="+" operand2="1" datatype="int" />
  </sequential>
</for>

<echoproperties prefix="var" />
Run Code Online (Sandbox Code Playgroud)

输出:

[echoproperties] var1=piyush
[echoproperties] var2=kumar
Run Code Online (Sandbox Code Playgroud)

这一切都非常非蚂蚁 - 一旦你设定了这些你将要做什么?

您可以考虑使用Ant script任务代替此类非声明性处理.