I would like to do something like this
Alternately, once can include the following line in your ANT script
<taskdef resource="net/sf/antcontrib/antlib.xml" />
As long as ant-contribs
is in your path, nothing else is needed
This solution is a bit cleaner, as one gains access to ALL the tags, not just the ones manually specified
I got the same issue. I resolved in the following way. Sometimes this might be compatibility problem.
Same issue resolved in that way. I put at the start of the buid XML file the following lines:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="your/path/to/ant-contrib-${version}.jar" />
</classpath>
</taskdef>
On the tasks tab for your Ant Runtime do you see the 'if' task?
The standard ant way would be something like =
<target name="check">
<condition property="delbuild">
<available file="${build}" type="dir"/>
</condition>
</target>
<target name="delbuild" depends="check" if="delbuild">
<delete dir="${build}"/>
<!-- .. -->
</target>
A snippet with the Ant Plugin Flaka, a recent alternative to antcontrib. Installation in Eclipse as usual via
Preferences | Ant | Runtime | Global Entries | ant-flaka-1.02.-1.02.jar =
<project xmlns:fl="antlib:it.haefelinger.flaka">
<!-- some standalone if construct -->
<fl:when test=" '${build}'.isdir ">
<delete dir="${build}"/>
</fl:when>
<!-- some if/then/else construct -->
<fl:choose>
<!-- if -->
<when test=" '${buildtype}' eq 'prod' ">
<!-- then -->
<echo>..starting ProductionBuild</echo>
</when>
<when test=" '${buildtype}' eq 'test' ">
<!-- then -->
<echo>..starting TestBuild</echo>
</when>
<!-- else -->
<otherwise>
<fl:unless test="has.property.dummybuild">
<fail message="No valid buildtype !, found => '${buildtype}'"/>
</fl:unless>
<echo>.. is DummyBuild</echo>
</otherwise>
</fl:choose>
</project>
output with ant -f build.xml -Dbuildtype=prod or
ant -f build.xml -Dbuildtype=prod -Ddummybuild=whatever
[echo] ..starting ProductionBuild
output with typo => ant - build.xml -Dbuildtype=testt
BUILD FAILED
/home/rosebud/workspace/AntTest/build.xml:21: No valid buildtype !, found => 'testt'
output with ant -f build.xml -Ddummybuild=whatever
[echo] .. is DummyBuild
export ANT_HOME=/path/to/ant/apache-ant-1.8.2
I couldn't get it to work until I had ANT_HOME set properly. Java kept picking another ant installed on the box.