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

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

问题描述

我在第三方库中的类中收到NullPointerException。现在我想调试整个事情,我需要知道从哪个对象举办该类。但是在我看来,我不能在第三方的Class中设置断点。有人知道有什么办法摆脱了我的困扰吗?

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.

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

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