关于java的编译跟远程调试
关于java的编译和远程调试
场景:
远程服务器上的java程序使用ant编译,本地java程序使用eclipse编译,远程调试服务器上的java程序。
基本的条件比如要用相同版本的jdk编译是前提,这里着重强调相关的编译条件。
设置 :
1.本地eclipse编译时,需要工程右键->属性->Java Compiler->Classfile Generation
勾选下面的Add variable attributes ...
Add line number attributes ...
Add source file name ...
Preserve unused local variables
2.远程服务器上使用ant编译时,javac任务添加属性debug="on" debuglevel="vars ,lines ,source "
结论 :
对比上面的设置,我们可以看出,我们要能按行debug,并且看到变量值的话,要保证eclipse和ant编译的参数都相同。
当然这只是调试时需要的配置,真正上线运行的代码,编译时要关闭debug信息,即debug="off"。
在eclipse中可能会出现的错误:
- 设置断点时,报:Unable to install breakpoint due to missing line number attributes. Modify compiler options to generate line number attributes错误。
解决办法:首先按上面的第一条配置eclipse,另外在ant的javac任务中打开debug属性,即debug="on"
- 现在可以调试了,但是只能看到this的变量,local variables都没有显示
解决办法:相信你看了上面的2条应该知道怎么办了吧?