在 Eclipse 中附加源问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/191998/
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
Attach Source Issue in Eclipse
提问by Paul Croarkin
In Eclipse (Ganymede) I'm debugging some code that uses Apache Commons HttpClient and would like to step into the HttpClient code. I've downloaded the source code and tried to attach it in the normal fashion (CTRL-click on the method name and use the Attach Source button). I've tried to attach both as external file and external folder with no success. I've attached source before with no issues and can currently step into Hibernate source code successfully.
在 Eclipse (Ganymede) 中,我正在调试一些使用 Apache Commons HttpClient 的代码,并希望进入 HttpClient 代码。我已经下载了源代码并尝试以正常方式附加它(CTRL-单击方法名称并使用附加源按钮)。我试图同时附加作为外部文件和外部文件夹,但没有成功。我之前已经附加了源代码,没有任何问题,目前可以成功进入 Hibernate 源代码。
I've even tried editing the .classpath file directly to add sourcepath manually. Still no luck. Refreshing the project, doing a clean build, closing and re-opening Eclipse do not solve the issue. Frustratingly, Eclipse provides no error message; it just does not attach the source.
我什至尝试过直接编辑 .classpath 文件以手动添加源路径。仍然没有运气。刷新项目、进行干净的构建、关闭并重新打开 Eclipse 都不能解决问题。令人沮丧的是,Eclipse 没有提供任何错误消息;它只是不附加源。
Here are the entries in .claspath:
以下是 .claspath 中的条目:
<!-- Hibernate. Works -->
<classpathentry kind="lib" path="/myEAP/EarContent/APP-INF/lib/hibernate.jar" sourcepath="D:/Data/Download/hibernate-3.2.2.ga/hibernate-3.2/src"/>
<!-- Commons HttpClient. Will not attach -->
<classpathentry kind="lib" path="/myEAP/EarContent/APP-INF/lib/commons-httpclient.jar" sourcepath="D:/Data/Download/commons-httpclient-3.1/src/java"/>
I've tried changing the path to D:/Data/Download/commons-httpclient-3.1/src and that does not work either.
我已经尝试将路径更改为 D:/Data/Download/commons-httpclient-3.1/src 并且这也不起作用。
The directory structure is:
目录结构为:
D
Data
Download
commons-httpclient-3.1
src
java
org
apache
commons
httpclient
AutoCloseInputStream.java
... (and so forth)
回答by Dave L.
Try pointing it at a directory containing the top level package directly, "D:/Data/Download/commons-httpclient-3.1/src/java" for you. What worked for me was creating a new src zip file containing the "org" folder and everything beneath it.
尝试将其直接指向包含顶级包的目录,为您提供“D:/Data/Download/commons-httpclient-3.1/src/java”。对我有用的是创建一个新的 src zip 文件,其中包含“org”文件夹及其下的所有内容。
Here's my .classpath entry, (which works for me) in case it helps:
这是我的 .classpath 条目(对我有用)以防万一:
<classpathentry kind="lib" path="/blib/java/commons-httpclient-3.1/commons-httpclient-3.1.jar" sourcepath="/blib/java/commons-httpclient-3.1/commons-httpclient-3.1-src.zip"/>
回答by stolsvik
I've found that sometimes, you point to the directory you'd assume was correct, and then it still states that it can't find the file in the attached source blah blah.
我发现有时,您指向您认为正确的目录,然后它仍然指出它无法在附加的源代码中找到该文件等等。
These times, I've realized that the last path element was "src". Just removing this path element (thus indeed pointing one level above the actual path where the "org" or "com" folder is located) magically makes it work.
这些时候,我意识到最后一个路径元素是“src”。只需删除此路径元素(因此确实指向“org”或“com”文件夹所在的实际路径上方的一层)就可以神奇地使其工作。
Somehow, Eclipse seems to imply this "src" path element if present, and if you then have it included in the source path, Eclipse chokes. Or something like that.
不知何故,Eclipse 似乎暗示了这个“src”路径元素(如果存在),并且如果您将它包含在源路径中,Eclipse 就会窒息。或类似的东西。
回答by JeeBee
Try attaching the src.zip instead of the unzipped src?
尝试附加 src.zip 而不是解压的 src?
回答by Dave Dunkin
Try adding it to the source path of your launch configuration.
尝试将其添加到启动配置的源路径中。
回答by Daniel Spiewak
Attaching sources is not all that is required to step into a library on the classpath; that library must also be compiled with debug symbols. This usually isn't a problem, since most Java libraries are compiled and distributed in such a fashion, but as you have found, some of them are not.
附加源并不是进入类路径上的库所需的全部;该库还必须使用调试符号进行编译。这通常不是问题,因为大多数 Java 库都是以这种方式编译和分发的,但正如您所发现的,其中一些不是。
It is interesting to note that you can actually step into external libraries even without the source attached, you just can't see the line-by-line sources (all of the debug info still works).
有趣的是,即使没有附加源,您实际上也可以进入外部库,只是看不到逐行源(所有调试信息仍然有效)。
You could "fix" this problem by compiling a custom version of Commons HttpClient (not too difficult), or just skip the whole "step into the library" idea. As a general development practice, stepping into third-party libraries will rarely yield useful information. I've done it maybe once or twice in the last ten years, neither time did it actually bring me any closer to solving the dilemma at hand.
您可以通过编译 Commons HttpClient 的自定义版本来“修复”这个问题(不太难),或者只是跳过整个“步入库”的想法。作为一般的开发实践,进入第三方库很少会产生有用的信息。在过去的十年里,我可能做过一两次,但实际上这两次都没有让我更接近解决手头的困境。
回答by Evgeny P
I think, problem in space (or localized) simbols in path to source archive. Try to move it to another place with simple path.
我认为,源存档路径中的空间(或本地化)符号问题。尝试使用简单的路径将其移动到另一个地方。