Attach Source Issue in Eclipse

2019-04-09 08:56发布

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.

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.

Here are the entries in .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.

The directory structure is:

D
  Data
    Download
      commons-httpclient-3.1
        src
          java
            org
              apache
                commons
                  httpclient
                    AutoCloseInputStream.java
                    ... (and so forth)

6条回答
Animai°情兽
2楼-- · 2019-04-09 09:39

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.

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.

查看更多
三岁会撩人
3楼-- · 2019-04-09 09:40

I think, problem in space (or localized) simbols in path to source archive. Try to move it to another place with simple path.

查看更多
叛逆
4楼-- · 2019-04-09 09:41

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.

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.

查看更多
Rolldiameter
5楼-- · 2019-04-09 09:45

Try attaching the src.zip instead of the unzipped src?

查看更多
叼着烟拽天下
6楼-- · 2019-04-09 09:49

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.

Here's my .classpath entry, (which works for me) in case it helps:

<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"/>
查看更多
Bombasti
7楼-- · 2019-04-09 09:49

Try adding it to the source path of your launch configuration.

查看更多
登录 后发表回答