Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANT: Using conditional tags, <IF>

I would like to do something like this

<target name="clean" description="clean">
    <if>
        <available file="${build}" type="dir" />
        <then>
            <delete dir="${build}" />
        </then>
    </if>
</target>

As per suggestions found on stackoverflow.com, i downloaded ant-contrib-1.0b3.jar and put it into my path

Classpath

Additionally, under Ant Build configuration, in classpath, i have enter image description here

When running my ANT script, i still get

BUILD FAILED
C:\Repositories\blah\build.xml:60: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

What am i missing? Please advise

like image 486
James Raitsev Avatar asked Jun 13 '11 21:06

James Raitsev


People also ask

How to use if else in Ant?

If the condition on the <if> is false, then the first <elseif> who's conditional evaluates to true will be executed. The <else> will be executed only if the <if> and all <elseif> conditions are false.

Are ants case sensitive?

The Ant tasks process these files in a case-sensitive way.

What is Isset in ant?

isset is a conditional to test whether a given property has been set.

What is target in Ant build?

A target is a container of tasks and datatypes that cooperate to reach a desired state during the build process. Targets can depend on other targets and Apache Ant ensures that these other targets have been executed before the current target.


2 Answers

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.

like image 85
ddtraveller Avatar answered Sep 21 '22 20:09

ddtraveller


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>
like image 40
user3276092 Avatar answered Sep 21 '22 20:09

user3276092