如何在ant构建创建的jar的错误堆栈跟踪中获取源行号?

时间:2022-08-23 20:45:02

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.

我正在使用ant在eclipse中构建项目的jar。我将该jar部署到tomcat上。但是,每当我的代码(在jar中)发生异常时,错误堆栈跟踪就会出现,但是行号不会出现——相反,它会显示未知源。

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

如何在错误堆栈跟踪中获取行号?

2 个解决方案

#1


19  

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:

您需要使用调试信息编译jar。具体地说,您需要找到javac任务,该任务编译您稍后jar的类并添加debug="on"属性。例子:

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

Full details can be found here.

完整的细节可以在这里找到。

#2


4  

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.

属性“debug”要求值为“true”或“false”,并转换为javac -g选项。当显式地想要为-g指定一个参数时,可以通过定义属性“debuglevel”来实现,该属性接受“source”、“vars”和其他值(更多细节请参见ant任务文档)。设置debug="true"和debuglevel="source"将附加源代码,但不会提供行号信息,debug=" lines,vars,source"将提供您需要的信息。

#1


19  

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:

您需要使用调试信息编译jar。具体地说,您需要找到javac任务,该任务编译您稍后jar的类并添加debug="on"属性。例子:

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

Full details can be found here.

完整的细节可以在这里找到。

#2


4  

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.

属性“debug”要求值为“true”或“false”,并转换为javac -g选项。当显式地想要为-g指定一个参数时,可以通过定义属性“debuglevel”来实现,该属性接受“source”、“vars”和其他值(更多细节请参见ant任务文档)。设置debug="true"和debuglevel="source"将附加源代码,但不会提供行号信息,debug=" lines,vars,source"将提供您需要的信息。