2015-04-01 110 views
1

在我的Ant构建我有以下代码:蚂蚁在try catch块失败

<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> 

蚂蚁说:

问题:无法创建任务或键入trycatch
原因:名称未定义。 操作:检查拼写。
操作:检查是否声明了任何自定义任务/类型。
操作:检查是否发生了任何/声明。

我在这里错过了什么?

//编辑:我在Eclipse

回答

1

trycatch使用ANT被Ant-Contrib第三方库提供的任务。确保下载他们的Jar并在Ant类路径中引用它。有关如何操作,请参阅this link

在Eclipse上,转到窗口 - >首选项 - > Ant - >运行时。在类路径选项卡下,使用“添加外部JAR ...”按钮添加Ant-Contrib jar。正如链接中所述,您需要声明以下任务:

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

我在日食中使用ANt。我应该如何设置? – user3631654 2015-04-01 12:51:59

+1

使用antcontrib.properties的taskdef定义错误。 antcontrib.properties只包含ant <1.6的taskdefs,声明它(假设antcontrib.jar已经在路径上): ... 或没有命名空间:<! - 进口AntContrib - > <的taskdef资源= “网/平方英尺/ antcontrib/antlib.xml”/> ... – Rebse 2015-04-02 12:41:26