如何在第三方库中的 Eclipse 中设置断点? [英] How to set a breakpoint in Eclipse in a third party library?

查看:17
本文介绍了如何在第三方库中的 Eclipse 中设置断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在来自第 3 方库的类中收到 NullPointerException.现在我想调试整个过程,我需要知道该类是从哪个对象中保存的.但在我看来,我无法在第 3 方的类中设置断点.

I'm getting a NullPointerException in a Class from a 3rd party library. Now I'd like to debug the whole thing and I would need to know from which object the class is held. But it seems to me that I cannot set a breakpoint in a Class from a 3rd party.

有谁知道解决我的麻烦的方法吗?当然,我使用 Eclipse 作为我的 IDE.

Does anyone know a way out of my trouble? Of course I'm using Eclipse as my IDE.

更新:该库是开源的.

推荐答案

最可靠的方法(并最终得到真正有用的东西)是下载源代码(你说它是开源的)),并设置另一个指向该源的Java 项目".

The most sure-fire way to do this (and end up with something that's actually useful) is to download the source (you say that it is open-source), and set up another "Java Project" pointing at that source.

要做到这一点,请下载源代码并将其解压缩到系统的某个位置.单击文件"->新建"->Java 项目".在下一个对话框中,为其指定一个项目名称并选择从现有源创建项目".浏览到开源库的根位置.

To do that, get the source downloaded and unzipped somewhere on your system. Click "File"->"New"->"Java Project". In the next dialog, give it a project name and select "Create Project from Existing Source". Browse to the root location of the open source library.

假设项目所需的所有附加库等都包含在您下载的项目中,Eclipse 会计算出所有内容并为您设置构建路径.

Supposing that all the additional libraries that are required by the project and such are included in the project you downloaded, Eclipse will figure everything out and set the build path up for you.

您需要从项目的构建路径中删除开源 jar,并将此新项目添加到项目的构建路径中.

You'll need to remove the open source jar from your project's build path, and add this new project to the build path of your project.

现在,你可以把它当作你的代码,随意调试.

Now, you can just treat this as your code, and debug at will.

这至少解决了其他方法的一些问题:

This gets around at least a couple of problems with other approaches:

  1. 您可以附加源代码"到 jar 文件,但是如果 jar 文件是在没有调试信息的情况下编译的,这仍然不起作用.如果 jar 文件是使用调试信息编译的(lines,source,vars...参见 http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javac.html-g选项).

  1. You could "attach source" to the jar file, but if the jar file was compiled without debug information, this still won't work. If the jar file was compiled with debug information (lines,source,vars...see http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javac.html, and the -g option).

您可以添加一个异常断点"来查看 NullPointerException 何时引发,但这是一个常见的异常,并且很可能在您遇到的异常之前引发和处理许多(数百?)次寻找.另外,如果没有原始来源,您将无法真正看到有关抛出 NullPointerException 的代码的任何信息 - 您能够找出问题所在的可能性非常低.

You could add an "exception breakpoint" to see when the NullPointerException is raised, but that's a common exception, and may well get raised and dealt with many (hundreds of?) times prior to the one you're looking for. Plus, without the original source, you won't be able to really see much of anything about the code that is throwing the NullPointerException - the likelihood you'll be able to figure out what's wrong is pretty low.

这篇关于如何在第三方库中的 Eclipse 中设置断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆