The Ant-Contrib library also provides u a <for> task to do iteration. Here is an simple Ant example which read a text files and print it to the Ant build output.
1. This is the structure of our Ant project.
ant-for-example | - ant-lib | | - ant-contrib-1.0b3.jar | - build.xml | - text.txt
2. text.txt
1. Hello World 2. Welcome to Eureka! 3. Goodbye
3. build.xml
<project name="ant-for-example" default="read" basedir="."> <!-- Load the ant contrib lib --> <taskdef resource="net/sf/antcontrib/antlib.xml"> <classpath> <pathelement location="${basedir}/ant-lib/ant-contrib-1.0b3.jar"/> </classpath> </taskdef> <target name="read"> <loadfile property="textFile" srcfile="${basedir}/text.txt"/> <for param="line" list="${textFile}" delimiter="${line.separator}"> <sequential> <echo message="@{line}"/> </sequential> </for> </target> </project>
4. Try it out.
Image may be NSFW.
Clik here to view.
Done =)
Reference:
- StackOverflow – Ant: Not recognizing FOR task
- StackOverflow – How to read data line by line from a file using ant script?
Filed under: Ant Tagged: Ant, Ant-Contrib Image may be NSFW.
Clik here to view.

Clik here to view.
