今天以前的同事问我这个问题,我也不知道为什么。
问题是:当DEBUG自己程序的时候,调用了第三方的类库——比如JDK自己的类库——我们有这些类库的源码,进入随源码进入类库后,你会发现代码运行的行会在调试下一步步走,但鼠标指向变量时不再显示变量的值,选中->右键->watch也不能看到变量的值,什么原因?
我以前经常遇到这些问题,但从来没想过为什么不行,以为不是自己的类库就不显示,实际情况并非如此。
于是同事查了一下原因,发给了我,我就直接贴在这儿了。
Debug into rt.jar
August 4th, 2007
If you ever use Eclipse trying to debug into Java’s system APIs, such as java.lang.String or java.math.BigInteger, you may find that even you can step over or step in, or have the correct source file open and the correct line of codes highlighted, you still
could not see the local variables’ value and method’s parameters are shown in pattern of “arg0″, “arg1″ and so on.
Yes, you are already using JDK instead of JRE. But you still have the above problem. What’s wrong? It’s not a bug of Eclipse. It is all about the rt.jar along with the JDK (1.5 or 1.6). In Sun’s official JDK release, debug symbols are already packed into the
rt.jar. But local variables’ debug information is not packed. Sun may consider that it is not OK to includes those local variables’ debugging information. That is the source of problem.
To solve this problem, you may need to upgrade to JDK 1.6. Download DEBUG jar file from
http://download.java.net/jdk6/binaries/
Double click it to install a new JDK. And configure your Eclipse to use the new JDK.
For JDK 1.5, recompiling rt.jar by yourself, or other information, please visit
http://forums.java.net/jive/thread.jspa?threadID=399&tstart=0
for a detailed discussion.
这段描述只是针对rt.jar的:上面大概的意思是当rt.jar类库发布时,它们把调试标记打在了JAR包中,但局部变量的DEBUG信息并未打包。他们可能是出于“本地变量的调试信息包含在JAR包中并不好”的考虑,所以没有这么做,这就是问题的根源。
如果你想解决类似问题,你需要专门下载安装带这类信息的JDK......就是重装了JDK啦。
我觉得既然人家发布了,按一般的逻辑就认为它不会有BUG,如果你用了第三方类库,就认为你对它内部的运行方式已经了解,所以你不需要查找别人JAR包的BUG。如果真有BUG并且正好被你运行到了,那你就中奖喽。
----------------------------------------------------高兴的分界线--------------------------------------------------
1.把jdk中的src.zip解压缩
2.在elipse建立新的java项目
这时候会报很多错,不用鸟它就行。
3.将项目导出为jar格式
4.将新导出的jar包加入到Installed JRES
5.这个时候再调试就会有值了