1
votes

In my ANT build I have the following code:

<trycatch reference="exception_ref">
    <try>
        <echo>Start Building Delivery</echo>
    </try>
    <catch>
        <property name="exception" refid="exception_ref" />
        <property name="message" value="Error in trycatch block:${line.separator}${exception}" />
        <echo message="${message}" />
        <fail message="${message}" />
    </catch>
    <finally>
        <echo>Finally</echo>
    </finally>
</trycatch>

Ant says:

Problem: failed to create task or type trycatch
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.

What am I missing here?

// EDIT: I am using ANT in Eclipse

1

1 Answers

1
votes

trycatch is a task provided by the Ant-Contrib third-party library. Make sure to download their Jar and have it referenced on the Ant classpath. See this link for how to do this.

On Eclipse, go to Window -> Preferences -> Ant -> Runtime. Under the Classpath tab, add the Ant-Contrib jar using the "Add External JARs..." button. And as mentioned in the link, you need to declare the tasks as follows:

<taskdef resource="net/sf/antcontrib/antlib.xml"/>