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

二次信任 提交于 2019-12-08 15:30:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!