Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.

 

 
 

 

In some cases, ANT has it’s limitations. For example, it is not really easy to create an if-else structure or a for-loop. For this reason, a few people started long time ago the Ant-Contrib project. Just download it and put the jar file in the lib folder of the project. Then, just at following line to the build file:

<taskdef resource="net/sf/antcontrib/antcontrib.properties"></taskdef>

Now, you can start using constructs like if, foreach and combine these tasks with usual ANT tasks. Here a little example:

with antcontrib:

<target name="theultimateconditionmachine">
  <if>
    <equals arg1="${foo}" arg2="bar" />
    <then>
      <echo message="property foo is bar" />
    </then>
    <else>
      <echo message="property foo is not bar" />
    </else>
  </if>
</target>

without antcontrib:
if you want to perform the same task with ant, you need to create 4 (!) ant targets:

<target name="noway">
  <antcall target="conditionIf"/>
  <antcall target="conditionElse"/>
</target>
 
<target name="conditionDef">
  <condition property="conditionIsTrue">
    <equals arg1="${foo}" arg2="bar"/>
  </condition>
</target>
 
<target name="conditionIf" depends="conditionDef" if="conditionIsTrue">
  <echo message="property foo is bar"/>
</target>
 
<target name="conditionElse" depends="conditionDef" unless="conditionIsTrue">
  <echo message="property foo is not bar"/>
</target>

 

 

 

 

 
Leave a comment