简体   繁体   English

如何显示构建失败与蚂蚁

[英]how to display build failed with ant

I am using a fake ant(we have our own version of ant that at some point calls the original ant) to run a java applciation. 我正在使用伪造的蚂蚁(我们有自己的ant版本,在某些时候称为原始ant)来运行Java应用程序。 The I run the application I want ant to display Build Failed whenever there is an exception thrown in the code. 每当代码中引发异常时,我都会运行我希望蚂蚁显示Build Failed的应用程序。

Right now what is happening is that if I throw an exception in the code, the ant displays the exception on the terminal but writes Build Successful in the end. 现在发生的事情是,如果我在代码中抛出异常,则蚂蚁会在终端上显示该异常,但最后会写入Build Successful How can I make the build fail in the case of any exception ? 如果出现任何异常,如何使构建失败? Even if I exit the program by writing System.exit(1) it writes Java Result: 1 but still writes that the Build was successful. 即使我通过写System.exit(1)退出程序,它也会写Java Result: 1但仍然写出Build成功。 I am using try/catch in the build.xml file but it doesn't help. 我在build.xml文件中使用try / catch,但没有帮助。

The ant target in the build file looks like this. 构建文件中的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>

Now, what I want is that if there is any exception thrown during the execution of the program, it should display build failed and not build successful. 现在,我想要的是,如果在程序执行过程中引发任何异常,它应该显示构建失败而不是构建成功。

Any ideas ? 有任何想法吗 ?

使用failonerror属性:

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

您可以使用 :

failonerror="true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM