Java Eclipse - 找不到源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21884378/
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
Eclipse - Source not found
提问by stdout
I know this question has been asked many times before, but none of the proposed solutions resolve my issue (or I'm not implementing them correctly).
我知道这个问题之前已经被问过很多次了,但是没有一个提议的解决方案能解决我的问题(或者我没有正确实施它们)。
I'm developing a plugin for OpenFire, and when I set a breakpoint in my plugin source Eclipse reports "Source not found". The JAR is built separate from the build of the OpenFire server. I've tried adding the JAR and specifying the source code directory, but no dice.
我正在为 OpenFire 开发一个插件,当我在插件源中设置断点时,Eclipse 报告“找不到源”。JAR 与 OpenFire 服务器的构建分开构建。我已经尝试添加 JAR 并指定源代码目录,但没有骰子。
Here's the process I'm following: When I hit my breakpoint I'm clicking "Edit Source Lookup Path", clicking "Add", Java Library, User Library, click User Libraries, adding my library (tried both "Add JARs" and "Add External JARs"), and then specifying the folder that contains the source code. I've also tried:
这是我正在遵循的过程:当我点击断点时,我单击“编辑源查找路径”,单击“添加”,Java 库,用户库,单击用户库,添加我的库(尝试了“添加 JAR”和“添加外部 JAR”),然后指定包含源代码的文件夹。我也试过:
- Adding the source by selecting "File System Directory" instead of "Java Library"
- Adding it by selecting "Workspace Folder"
- In the Project Explorer, adding the source for my plugin to the Java Build Path
- In the Project Explorer, adding my JAR as a Library and specifying the Source attachment
- 通过选择“文件系统目录”而不是“Java 库”来添加源
- 通过选择“工作区文件夹”添加它
- 在 Project Explorer 中,将我的插件的源代码添加到 Java Build Path
- 在项目资源管理器中,将我的 JAR 添加为库并指定源附件
Thanks in advance for any suggestions.
在此先感谢您的任何建议。
采纳答案by stdout
Well it turns out the solution was anticlimactic. When Balder's recommendations did not work I tried debugging one of the stock OpenFire plugins and it worked just fine. I then created a new plugin from scratch, and by doing nothing other than adding the source to the project (Right-click on the project -> New -> Source Folder) it also worked just fine. I have no idea why Eclipse refuses to see the source for my original plugin, but I moved all my code and libraries over to the new plugin and debugging is working as expected.
事实证明,解决方案是虎头蛇尾的。当 Balder 的建议不起作用时,我尝试调试一个常用的 OpenFire 插件,它运行得很好。然后我从头开始创建了一个新插件,除了将源添加到项目(右键单击项目 -> 新建 -> 源文件夹)之外什么都不做,它也工作得很好。我不知道为什么 Eclipse 拒绝查看我的原始插件的源代码,但我将所有代码和库移到了新插件中,并且调试按预期工作。
回答by Balder
Personally, I have no good experience in Eclipse JDT, when adding a source folder at the time it hits a break point. What I always prefer to do, is adding the source folder before debugging:
就个人而言,我在 Eclipse JDT 中没有很好的经验,在它遇到断点时添加源文件夹。我总是喜欢在调试之前添加源文件夹:
- Select Project/Properties/Libraries
- Select your library and "edit..." the source attachment
- Select either the corresponding source folder or the zip/jar containing the package
- 选择项目/属性/库
- 选择您的库并“编辑...”源附件
- 选择相应的源文件夹或包含包的 zip/jar
After that, you should be able to open the source filesin the virtual "Referenced Libraries" folder (directly below the "JRE System Library" folder inside the project), or when opening a reference to a linked class file from within the JDT editor. If you are able to access the source, then you should also be able to at least stop at the break point and see the corresponding source.
之后,您应该能够打开虚拟“引用库”文件夹中的源文件(直接在项目内的“JRE 系统库”文件夹下方),或者在 JDT 编辑器中打开对链接类文件的引用时. 如果您能够访问源代码,那么您至少也应该能够在断点处停下来查看相应的源代码。
Else, you will have to check again, if the source folder is really valid: The source folder or source archive must contain the folder with the name of the root package of the library (e.g. the default Java "src.zip" inside the JDK folder also includes a corresponding "java" folder at its root). When in doubt, extract the archive and select the parent folderof the package you are interested in - sometimes source archives might be a mess or incompatible to JDT.
否则,您将不得不再次检查源文件夹是否真的有效:源文件夹或源存档必须包含具有库根包名称的文件夹(例如,JDK 中的默认 Java“src.zip”文件夹在其根目录中还包含一个相应的“java”文件夹)。如有疑问,请提取存档并选择您感兴趣的包的父文件夹- 有时源存档可能会很混乱或与 JDT 不兼容。
If this has been assured and it still doesn't work, chances are, that your linked source folder does not correspond to the compiled version of the library. Usually JDT will handle such inconsistencies fine, but if you try to open a source file, that is entirely different than the corresponding class file, you will encounter problems. In this case I would suggest either downloading the correct source version of the library, or recompiling the library from the source, if all else fails.
如果这已经得到保证但它仍然不起作用,很可能是您链接的源文件夹与库的编译版本不对应。通常 JDT 会很好地处理这种不一致,但是如果您尝试打开与相应类文件完全不同的源文件,则会遇到问题。在这种情况下,我建议要么下载正确的库源版本,要么从源重新编译库,如果一切都失败了。
If opening a referenced source file from withing the JDT editor does work fine, and you are still unable to open the source files when a break point is entered during debugging, then most likely the class files are missing the line numbersof the corresponding source file. Again, you will have to recompile the library from the source in this case.
如果使用 JDT 编辑器打开引用的源文件工作正常,并且在调试期间进入断点时仍然无法打开源文件,则很可能是类文件缺少相应源文件的行号. 同样,在这种情况下,您必须从源代码重新编译库。
Finally, it is also possible to overwrite the default source lookup by specifying source folders or archives in the source tab of the launch configuration. But you should normally not need to do this, when your build path is configured correctly. From the Eclipse Help:
最后,还可以通过在启动配置的源选项卡中指定源文件夹或存档来覆盖默认源查找。但是,当您的构建路径配置正确时,您通常不需要这样做。从Eclipse 帮助:
The Source tab defines the location of source files used to display source when debugging a Java application. By default, these settings are derived from the associated project's build path. You may override these settings here.
Source 选项卡定义了在调试 Java 应用程序时用于显示源代码的源文件的位置。默认情况下,这些设置源自关联项目的构建路径。您可以在此处覆盖这些设置。
回答by jmail
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. As a result, I constantly had to keep pressing the button to continue code execution.
我真的不需要知道这一点,因为异常被捕获和处理,但是每次发生这种情况时 eclipse 都会暂停调试并告诉我源不可用。结果,我不得不不断按下按钮才能继续执行代码。
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"
3. Unchecked "Caught"
This prevented the debugger from pausing program flow during a caught NullPointerException.alt text
这阻止了调试器在捕获 NullPointerException.alt 文本期间暂停程序流
(source: SharpDetail.com)
(来源:SharpDetail.com)
And this another one as:
这是另一个:
Eclipse doesn't crash. You're trying to step into a method, where eclipse doesn't know where to find the source (*.java) files and informs you about this. Here is how to tell eclipse where to look. Go to
Eclipse 不会崩溃。您正在尝试进入一种方法,在该方法中 eclipse 不知道在哪里可以找到源 (*.java) 文件并通知您这一点。这是告诉 eclipse 在哪里看的方法。去
Window->Preferences->Java->Installed JREs,select the JRE you are using and click Edit.
There, select all of the jar files in the list you see and and click Source Attachment....
在那里,选择您看到的列表中的所有 jar 文件,然后单击源附件...。
In the window that shows up, select the fille src.zip, which is in your JDK folder (if you didn't uncheck it while installing the JDK). On the machine I'm on right now, that is
在出现的窗口中,选择 JDK 文件夹中的 src.zip(如果您在安装 JDK 时没有取消选中它)。在我现在使用的机器上,那就是
C:\Program Files\Java\jdk1.7.0_07\src.zip.
Save all your changes (possibly restart eclipse) and you won't see that error again.
保存所有更改(可能重新启动 eclipse),您将不会再次看到该错误。
回答by vimal krishna
Many times you put jar files in eclipse IDE as referenced libraries when binary version of application was downloaded. Usually done so by configuring the build path. But the binary does not have the source files. You have Binary version and source version of application.
很多时候,当下载应用程序的二进制版本时,您将 jar 文件作为引用库放在 Eclipse IDE 中。通常通过配置构建路径来实现。但是二进制文件没有源文件。您有应用程序的二进制版本和源版本。
One simple way is to download the source libraries that you also use maven to build the project. Keep somehwere, may be inside your project workspace.
一种简单的方法是下载您也使用 maven 构建项目的源库。保留一些东西,可能在您的项目工作区中。
Now while seeing the class file (from eclipse, jar exploded) you may see the source not found, fine.... there is a button below and click on that, a new window opens and there select add external folder.
现在,在看到类文件(来自 eclipse,jar 爆炸)时,您可能会看到未找到源代码,很好……下面有一个按钮并单击它,打开一个新窗口,然后选择添加外部文件夹。
Reference it to the src folder of the source you downloaded(not the binary one) and kept somewhere as said above and it will show the class details from that.
将它引用到您下载的源代码的 src 文件夹(不是二进制文件)并保存在上面所说的某个地方,它将显示类的详细信息。
回答by fr0g88
I fixed this issue with doing the following:
我通过执行以下操作解决了这个问题:
Click at the menu Window - Preferences - Debug - Step Filtering And check all the packages like the following image.
单击菜单窗口 - 首选项 - 调试 - 步骤过滤并检查所有包,如下图所示。
Then, debug again your project and thats it.
然后,再次调试您的项目,就是这样。
Best regards,
此致,
回答by Leonel López
In my case, I had a breakpoint in the class declaration. I mean in the next line.
就我而言,我在类声明中有一个断点。我的意思是在下一行。
public class GenerateInterface implements JavaCall {
公共类 GenerateInterface 实现 JavaCall {
So, the debugger stopped in that line and showed the following message:
因此,调试器停在该行并显示以下消息:
Source not found
未找到来源
I think unconsciously activate the breakpoint in that line.
我认为不自觉地激活了该行中的断点。