Reputation: 1962
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. The I run the application I want ant to display Build Failed
whenever there is an exception thrown in the code.
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. 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. I am using try/catch in the build.xml file but it doesn't help.
The ant target in the build file looks like this.
<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 ?
Upvotes: 1
Views: 1727
Reputation: 72254
Use the failonerror
attribute:
<java classname="x.y.z.ClassName" fork="true" spawn="${spawnDB}" failonerror="true">
Upvotes: 1