开发者

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

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 t开发者_开发技巧race comes but the line number does not come -- instead it says unknown source.

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜