lee
lee

Reputation: 246

Working with ANT and facing an issue

<target name="init">
    <mkdir dir="${build.dir}" />
    <if>
        <available file="../war" type="dir"/>
            <then></then>
        <else> 
            <mkdir dir="../war" />
        </else> 
    </if>
</target>

This is the code i am using to check if a folder exists, but getting the following error:

Cause: The name is undefined.

Action: Check the spelling.

Action: Check that any custom tasks/types have been declared.

Action: Check that any / declarations have taken place.

I have copied ant-contrib.jar in ANT_HOME/lib. where am i goin wrong?

Upvotes: 1

Views: 57

Answers (1)

Adam Rofer
Adam Rofer

Reputation: 6521

Given the example above, you can greatly simplify it:

<target name="init">
    <mkdir dir="${build.dir}" />
    <mkdir dir="../war" />
</target>

...since the mkdir task does nothing if the folder exists (see documentation).

If you're asking how to use if and then in ant, I recommend picking another example since each action in Ant tends to have its own conditionals built in.

Upvotes: 4

Related Questions