Monday, December 3, 2012

For task in ANT

We might require to use for task in the ANT scripts.

By default for task in not available with basic ANT installation

Using the ant-contrib jar file we can define "for" task in build script.

Copy the ant-contrib-version.jar to the ANT_HOME lib folder and in the build script add the following section

  <project name="SOA_OSB_Deployment" basedir="." default="init">
     <taskdef resource="net/sf/antcontrib/antlib.xml"/>
     <target name="init">
            <for list="1,2,3,4,5" param="letter">
<sequential>
<echo>Letter @{letter}</echo>
</sequential>
</for>
      </target>
  </project>

Note : we should use net/sf/antcontrib/antlib.xml  not  net/sf/antcontrib/antcontrib.properties

Also the ant-contrib-version.jar can be kept any location, but we need to explicitly tell ant script where to locate the file


<taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="/usr/share/ant/lib/ant-contrib-version.jar"/>
  </classpath>
</taskdef>

No comments:

Post a Comment