Home > Apache Ant, General, Technology > Ant for Loop

Ant for Loop


This post explains you how to apply for-each iteration in your ant build script.

Prerequisite:

  1. You should’ve downloaded ant-contrib jar from http://ant-contrib.sourceforge.net/#install
  2. Add the jar into <ANT_HOME>/lib directory

Steps:

You first need to refer to your contrib jar in the <project> tag of build.xml


<?xml version="1.0" encoding="UTF-8"?>
<project name="ForTest" default="build" basedir="." xmlns:ac="antlib:net.sf.antcontrib">
 <taskdef uri="antlib:net.sf.antcontrib"
 resource="net/sf/antcontrib/antlib.xml"
 classpath="../../resources/ant/ant-contrib-1.0b3.jar"/>
 <target name="test">
 <echo message="The first five letters of the alphabet are:"/>
 <ac:for list="a,b,c,d,e" param="letter">
 <sequential>
 <echo>Letter @{letter}</echo>
 </sequential>
 </ac:for>
 </target>

 <target name="build" depends="test" description="Test For loop"/>
</project>

Save this as build.xml in your desired directory.

Note that specifying namespace ac: is extremely important to successfully execute build script.

Your script should execute and out put should get generated as shown below:

Advertisements
  1. July 20, 2014 at 3:09 PM

    Mediation: This is one of the most significant and cheaper alternative to hiring individual lawyers.
    If the situation or altercation presents itself in an act of misconduct at work.
    Taking an advantage of such a situation of car accident attorney, Jacksonville is making money with the huge number of cases filed each day.

    Like

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: