2012-07-02 120 views
1

我使用的是假的蚂蚁(我们有自己的蚂蚁版本,在某些时候调用原始蚂蚁)运行Java applciation。无论何时在代码中抛出异常,我都会运行应用程序,我希望ant能够显示Build Failed如何显示构建失败,蚂蚁

现在发生的事情是,如果我在代码中抛出异常,ant会在终端上显示异常,但最后会写入Build Successful。在任何异常情况下,如何使构建失败?即使我写 System.exit(1) 退出程序写入Java Result: 1但仍写道,构建成功。我在build.xml文件中使用try/catch,但它没有帮助。

在构建文件Ant目标看起来是这样的。

<target name="localhostIsAlive"> 
    <trycatch> 
     <try> 
      <java classname="x.y.z.ClassName" fork="true" spawn="${spawnDB}"> 
       <arg line="${version}"/>  
        <classpath> 
         <pathelement location="${basedir}/classes"/> 
        </classpath>        
      </java>    
     </try> 
     <catch> 
      <fail message="Some error occured, build should fail"/> 
     </catch> 
    </trycatch> 
</target> 

现在,我想要的是,如果在程序执行过程中抛出任何异常,它应该显示构建失败并且不会构建成功。

任何想法?

回答

1

使用failonerror属性:

<java classname="x.y.z.ClassName" fork="true" spawn="${spawnDB}" failonerror="true"> 
0

你可以使用:

failonerror="true"