tags:

views:

628

answers:

3
+4  Q: 

Ant: foreach loop

I'm trying to use the foreach loop in an Ant script but I get the message: Problem: failed to create task or type foreach Cause: The name is undefined.

I don't understand why this doesn't work. It is not a 3rd party library. It is a standard task that would be part of the latest version of Ant (1.8).

<target name="parse">
  <echo message="The first five letters of the alphabet are:"/>

  <foreach param="instance" list="a,b,c,d,e">

  </foreach>
</target>
+4  A: 

It is a standard task that would be part of the latest version of Ant (1.8).

No, it's not. At least I can't find it in the list of core and optional tasks in the ant manual. It seems to be part of the ant-contrib project and thus needs to be installed separately.

Michael Borgwardt
+1  A: 

I can't find the foreach task in the Ant 1.8 manual - where is it? I only know the task from ant-contrib, and it requires to specify the 'target' attribute: http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html

Chris Lercher
A: 

I had the same issue under eclipse with various versions of ant.

Add this into your code WITHOUT adding parameters under eclipse (do not specify any classpath) :

<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="/path/to/ant-contrib/ant-contrib-1.0b3.jar"/>
julia2020
When i say various version : ie 1.6 and 1.7... ^_^ but first try this as a 3th party.
julia2020