简体   繁体   English

Eclipse调试“找不到源”

[英]Eclipse debugging “source not found”

I just started using Eclipse so go easy on me ;). 我刚开始使用Eclipse,所以对我很轻松;)。 But when trying to debug a JUnit test case I get a dialog that states the the source is not found when I get to this line in the code in my test method: 但是当我尝试调试JUnit测试用例时,我得到一个对话框,指出当我在我的测试方法的代码中找到这行时找不到源代码:

Assert.assertEquals(1, contents.size());

I know I should probably go and try and download the source from somewhere, but I really don't want to because I have no interest in stepping into the JUnit code. 我知道我应该去尝试从某个地方下载源代码,但我真的不想这样做,因为我没有兴趣进入JUnit代码。 I have the JUnit runtime jar so Why does Eclipse expect me to have all the referenced tools source code in order to debug my own code (seems somewhat silly)? 我有JUnit运行时jar所以为什么Eclipse希望我拥有所有引用的工具源代码以调试我自己的代码(看起来有点傻)?

My main question is though, how can I tell Eclipse to skip this dialog when the source is not available and allow me to continue to debug my own code? 我的主要问题是,如果源不可用,我如何告诉Eclipse跳过此对话框并允许我继续调试自己的代码?

[Edit] [编辑]

I've isolated the cause of this. 我已经找到了原因。 It seems that Eclipse seems to think it needs the source when an exception is thrown by the internal JUnit code. 似乎Eclipse在内部JUnit代码抛出异常时似乎认为它需要源代码。 In general is there anyway to tell it that it doesn't and just have it throw up an error dialog of some kind instead? 一般来说,无论如何都要告诉它它没有,只是让它抛出某种错误对话框而不是?

I had this very annoying problem for a long time but was finally able to solve it. 我很长时间遇到了这个非常烦人的问题,但终于能够解决它了。 In my case, a null pointer exception was being thrown somewhere in Java's Transformer.IsRuntimeCode(ProtectionDomain ) function. 在我的例子中,在Java的Transformer.IsRuntimeCode(ProtectionDomain )函数中抛出了一个空指针异常。

I didn't really need to know about this since the exception was being caught and handled, but eclipse would pause debugging every time this happened and tell me that the source wasn't available. 我真的不需要知道这个,因为异常被捕获和处理,但eclipse会在每次发生这种情况时暂停调试,并告诉我源代码不可用。 As a result, I constantly had to keep pressing the button to continue code execution. 结果,我不断地按下按钮继续执行代码。

In order to prevent this from happening, I: 为了防止这种情况发生,我:

  1. Clicked on the "Breakpoints" window at the bottom of the debugging screen 单击调试屏幕底部的“断点”窗口
  2. Right clicked "NullPointerException" 右键单击“NullPointerException”
  3. Unchecked "Caught" 未选中“抓住”

This prevented the debugger from pausing program flow during a caught NullPointerException. 这阻止了调试器在捕获的NullPointerException期间暂停程序流。

替代文字
(source: SharpDetail.com ) (来源: SharpDetail.com

The debug callstack will display a JUnit source code line when throwing an exception. 抛出异常时,调试调用堆栈将显示JUnit源代码行。
But you should not need to worry about that, if you do not have the source code of JUnit. 但是,如果您没有JUnit的源代码,则不必担心。

If you go back one line in the callstack, you should see the line (of your source code) which has caused the JUnit exception. 如果你回到一行在调用堆栈,你应该看到这已经引起了JUnit异常( 你的源代码)行。
That should be enough to debug your code. 这应该足以调试您的代码。


To associate the source with JUnit, you could add the junit.jar in the librairies of your project, and associates the junit-xyz-src.jar to the junit-xyzjar , like so : 要将源与JUnit关联,您可以在项目的库中添加junit.jar ,并将junit-xyz-src.jarjunit-xyzjar如下所示

http://web.archive.org/web/20130227201940/http://img241.i_mageshack.us/img241/1412/eclipsejunitsrc.png

That will generate in the .classpath of your project a line like: 这将在项目的.classpath中生成如下行:

<classpathentry kind="lib" path="junit-x.y.z.jar" sourcepath="junit-x.y.z-src.jar">

Note: actually, there would be the full path of the junit[...].jar files in this classpathentry line. 注意:实际上,这个classpathentry行中将有junit[...].jar文件的完整路径。 But you could also use Linked resources to avoid that fixed value (the full path) in your .classpath file. 但您也可以使用链接资源来避免.classpath文件中的固定值(完整路径)。

I had a similar problem. 我遇到了类似的问题。 I fixed it by right clicking on the project folder in the package explorer and selecting refresh. 我通过右键单击包浏览器中的项目文件夹并选择刷新来修复它。 The code source was out of sync with the debugger and this corrected it. 代码源与调试器不同步,并对此进行了更正。 The Transformer.IsRuntimeCode(ProtectionDomain) Source not found message no longer appears. Transformer.IsRuntimeCode(ProtectionDomain)源找不到消息不再出现。

Use the Step Filter to avoid stepping through the ...junit... packages. 使用步骤过滤器以避免单步执行... junit ...包。 Right click on the stack trace and choose Filter Package. 右键单击堆栈跟踪,然后选择Filter Package。 You may have to turn on filtering first with Use Step Filters. 您可能必须先使用“使用步骤过滤器”打开过滤。 ~~~ ~~~

Calculate contents.size() on a separate line instead or set a breakpoint on the method. 在单独的行上计算contents.size(),或者在方法上设置断点。

Also note the junit view in Eclipse allows you to navigate the stack trace. 另请注意,Eclipse中的junit视图允许您导航堆栈跟踪。

I had a similar problem with another jar, even when I pointed to the source it would ask for it again. 我和另一个罐子有类似的问题,即使我指向它会再次要求它。 I was able to solve it by compiling the jar with debug="on" on ANT. 我能够通过在ANT debug="on"debug="on"编译jar来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM