Saturday, August 18, 2007

Ant javac: Unknow source in stacktrace

I,Nidhi and Kush at mChek were debugging some code and got following exception

Exception in thread ... java.lang.ClassCastException
at SearchCustomerAction.search(Unknown Source)
Some googling helped and we found the reason. It was obvious that Java compiler didn't generate the debugging information. But why? I thought I had not provided any extra javac parameters, and by default javac should generates debugging information (it actually generates line number and source file information by default, local variable information is not generated by default). So wats wrong?

Actually we had used Ant for our build and javac Ant task by default doesn't generate debugging information. So the debug flag need to be turned "on" explicitly, something like this:
<!-- build.xml -->
<project name="someProjectName" default="build" basedir=".">
<target name="build">
<javac srcdir="." destdir="." debug="on"/>
</target>
</project>
For more information see javac and ant javac task.

No comments: