Reputation: 65
I am invoking a Java Class through ant script. Is there any way in which we can display the error message of the Invoked Java class in the Ant Build Fail message?
Thanks
Upvotes: 0
Views: 534
Reputation: 65
With all due respect for the above answers. I think I got a simpler solution. While running the ant script, if we call the command with a -d option in the end, it displays a lot more information alongwith the failure reason for the java class also.
Hence, the command would be :
ant fileName.xml -d
Cheers!
Upvotes: 0
Reputation: 22867
Yes, it is possible.
<target name="test_java">
<java classname="Test">
<classpath>
<pathelement path="${cpath}"/>
</classpath>
</java>
</target>
The Test
class source code:
public class Test {
public static void main(String[] args) {
int a = 2;
System.out.println(String.valueOf(a/0));
}
}
The output:
test_java:
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Test.main(Test.java:7) Java
Result: 1
Upvotes: 1
Reputation: 11
I assume you are using the task to do this? If so, you can redirect stderr to a property with the errorproperty attribute, and then include that property in your message in the task. You would have to have failonerror="false" and have some other method of detecting the error (a based on the process status code perhaps).
Upvotes: 1