问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/5904242/how-can-i-get-the-source-line-number-in-error-stack-trace-of-a-jar-created-by-an