Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the source line number in error stack trace of a jar created by ant build?

Tags:

java

jar

javac

ant

I am using ant to build a jar of my project in eclipse. I deploy that jar on tomcat. But whenever an exception happen in my code (which is inside jar), the error stack trace comes but the line number does not come -- instead it says unknown source.

How can I get the line numbers in error stack trace?

like image 662
Ranger Avatar asked May 05 '11 21:05

Ranger


2 Answers

The attribute "debug" requires values of "true" or "false" and is translated to javac -g option.
When explicitly wanting to specify a argument to -g, you can do that by defining the
attribute "debuglevel" , which accepts "source", "vars" and other values (see ant task
documentation for more details).
Setting debug="true" and debuglevel="source" will attach the source but won't provide line
number informations, debuglevel="lines,vars,source" will give you the information
that you need.

like image 161
Peter Avatar answered Nov 05 '22 12:11

Peter


You need to compile your jar with debug information. Specifically, you need to find the javac task that compiles the classes that you later jar and add a debug="on" attribute. Example:

<javac srcdir="${src}"
     destdir="${build}"
     classpath="xyz.jar"
     debug="on"
     source="1.4" />

Full details can be found here.

like image 43
Itay Maman Avatar answered Nov 05 '22 11:11

Itay Maman