如何在 Eclipse 中调试已编译的 Java 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1905446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug compiled Java code in Eclipse
提问by NSPKUWCExi2pr8wVoGNk
I wonder if there are any solutions for Eclipse IDE to debug Java code for which I have no source, i.e. to debug dynamically decompiled code, step through it, etc.? I tried to use JD-Eclipse, JadClipse, and these plug-ins work great if I want to look at some class files, but as I debug, I get "Source not found." - how can I "attach" these plug-ins to "provide" source?
我想知道 Eclipse IDE 是否有任何解决方案来调试我没有源代码的 Java 代码,即调试动态反编译代码,单步执行等?我尝试使用JD-Eclipse、JadClipse,如果我想查看一些类文件,这些插件效果很好,但是在调试时,我得到“找不到源”。- 我如何“附加”这些插件以“提供”源代码?
My environment:
我的环境:
- Eclipse 3.5
- Windows XP (but I look for a cross platform solution, if possible)
- 日食 3.5
- Windows XP(但如果可能,我会寻找跨平台解决方案)
Thank you.
谢谢你。
采纳答案by Thorbj?rn Ravn Andersen
I have good experience with Jadclipse - http://jadclipse.sourceforge.net/wiki/index.php/Main_Page- there is an update site at http://jadclipse.sf.net/update
我对 Jadclipse 有很好的经验 - http://jadclipse.sourceforge.net/wiki/index.php/Main_Page- 在http://jadclipse.sf.net/update有一个更新站点
For best results, use jad and configure it to list line numbers as comments which will enable the output where the code is on the correct line. This is best for debugging sessions.
为了获得最佳结果,请使用 jad 并将其配置为将行号列为注释,这将启用代码在正确行上的输出。这最适合调试会话。
Then set it to be the default view for classes. See the documentation for details. This works well for me.
然后将其设置为类的默认视图。有关详细信息,请参阅文档。这对我很有效。
回答by David Rabinowitz
Decompile all the classes, put all the Java files ordered in the proper hierarchy (directory for package, etc.) and then add them as the source of the original jar by right clicking the jar file -> Java Source Attachment -> External folder.
反编译所有类,将所有 Java 文件按顺序放置在适当的层次结构(包目录等)中,然后通过右键单击 jar 文件 -> Java 源附件 -> 外部文件夹将它们添加为原始 jar 的源。
You can also have them inside a folder in the project (click on Workspace in this case)
您也可以将它们放在项目的文件夹中(在这种情况下单击工作区)
回答by user231960
This plugin should hopefully be of help. JD-Eclipse
这个插件应该有帮助。京东-日食
In eclipse open Window -> Preferences -> General ->Editors -> File Associations Select *.class file type Associate it with JD-Eclipse Set it to default
在eclipse中打开Window -> Preferences -> General ->Editors -> File Associations 选择*.class文件类型将其与JD-Eclipse关联设置为默认
Good Luck
祝你好运
回答by Emmanuel Dupuy
I have the same problem. Today, no decompilers are efficent to debug compiled Java code. I'm working on JD-Eclipse. In the next 3 to 6 months, the layout of JD-Eclipse should be really improved. We will start to debug classes without sources and solve some intractable problems.
我也有同样的问题。今天,没有反编译器可以有效地调试已编译的 Java 代码。我正在研究 JD-Eclipse。在接下来的 3 到 6 个月内,JD-Eclipse 的布局应该会得到真正的改进。我们将开始调试无源类并解决一些棘手的问题。
回答by sweetfa
You can use JD-GUI to decompile jar files and save the whole lot into a source zip file which can then be added to the source search list (via Configure Build Path).
您可以使用 JD-GUI 反编译 jar 文件并将整个文件保存到源 zip 文件中,然后可以将其添加到源搜索列表中(通过配置构建路径)。
The problem with JD-GUI is that the line numbers are out which makes debugging very difficult, so you need to
JD-GUI 的问题是行号出来了,这使得调试非常困难,所以你需要
- extract the source files from the decompiled source zip file
- Run the script found at https://bushlife.com.au/groups/python/wiki/7539a/Adjust_line_numbers_in_file.html
- zip the generated source back up
- add it as the source path associated with your java file - using Configure Build Path after right clicking on the jar file in your java project.
- 从反编译的源 zip 文件中提取源文件
- 运行在https://bushlife.com.au/groups/python/wiki/7539a/Adjust_line_numbers_in_file.html找到的脚本
- 将生成的源压缩备份
- 将其添加为与您的 java 文件关联的源路径 - 在您的 java 项目中右键单击 jar 文件后使用配置构建路径。
回答by avkosinsky
Realignment fragment for JD-Eclipse host plug-in. This plug-in for Eclipse makes the decompiled code line numbers actually appropriate to the line numbers from the java-class file. As a result, it becomes possible debugging without source code. https://sourceforge.net/projects/realignmentjd/
JD-Eclipse 主机插件的重新排列片段。这个 Eclipse 插件使反编译的代码行号实际上适合 java-class 文件中的行号。因此,无需源代码即可进行调试。https://sourceforge.net/projects/realignmentjd/
回答by Rafael
The solution that worked for me is using the JD-Eclipse after applying the patch: http://java.decompiler.free.fr/?q=node/464
对我有用的解决方案是在应用补丁后使用 JD-Eclipse:http: //java.decompiler.free.fr/?q=node/464
This is an extension of jd-eclipse which realigns the code after decompiling.
这是jd-eclipse的扩展,反编译后重新对齐代码。
When debugging with eclipse you just need to have the jar files in the classpath and that's it! There's no need to decompile the whole jar, realign or whatsoever... Just debug and be happy :-)
使用 Eclipse 进行调试时,您只需要在类路径中包含 jar 文件即可!无需反编译整个 jar、重新对齐或其他任何东西......只需调试并开心:-)
Here's how to do it: http://gauchoacomecable.wordpress.com/2011/10/14/eclipse-debug-java-without-source-code-jd-eclipse-and-realignment/
这是如何做到的:http: //gauchoacomecable.wordpress.com/2011/10/14/eclipse-debug-java-without-source-code-jd-eclipse-and-realignment/
回答by mchr
I have enhanced the "Realignment for JD Eclipse" plugin to properly line up enums and fields and published it along with JD Eclipse on my own update site: http://mchr3k-eclipse.appspot.com/
我已经增强了“JD Eclipse 重新对齐”插件以正确排列枚举和字段,并将其与 JD Eclipse 一起发布在我自己的更新站点上:http: //mchr3k-eclipse.appspot.com/
Details about my changes: http://mchr3k-coding.blogspot.co.uk/2012/07/realignment-for-jd-eclipse.html
有关我的更改的详细信息:http: //mchr3k-coding.blogspot.co.uk/2012/07/realignment-for-jd-eclipse.html