ant的javac任务里有对debug信息输出的设置,不过默认是不输出。
javac中设置调试信息级别的选项为-g,其详细含义如下,英文太简单,偶会详细介绍一下:
-g
Generate all debugging information, including local variables. By default, only line number and source file information is generated.
在Class文件中生成所有调试信息。也就是将会包含下面介绍的3类调试信息的所有。
-g:none
Do not generate any debugging information.
Class文件中不包含任何调试信息,这个是Ant在编译时默认使用的。
-g:
{keyword list}
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
source
Source file debugging information
Class文件中固定长度的SourceFile属性,编译时如果选择了生成此属性,则会将它写到Class文件中。它用来提供产生Class文件的源文件名称。
如果不生成此属性,那么在调试时就会提示“Source not found.”。
有图有真像,我们用Eclipse来演示一下此调试开关的作用,帮助大家理解。
先设置一下eclipse编译时的选项,关闭Source file属性开关,编译选项的修改只针对此测试用的工程,所以在我们测试的工程右键->properties,在弹出的对话框中,按下图进行选择:
public class Main {
public static void main(String[] args) {
Test t = new Test();
t.sayHello();
}
}
class Test
{
public Test() {
}
public void sayHello()
{
int a = 10; // 断点将打在此行
int b = a++;
System.out.println("b:" + b);
String hello = "Test say";
hello += " hello";
System.out.println(hello);
}
}
好了,我们在Eclipse中启动调试Main.java,你将会得到下图中的信息: