Is there an easy way to attach source in Eclipse?

2019-01-01 06:58发布

I'm a big fan of the way Visual Studio will give you the comment documentation / parameter names when completing code that you have written and ALSO code that you are referencing (various libraries/assemblies).

Is there an easy way to get inline javadoc/parameter names in Eclipse when doing code complete or hovering over methods? Via plugin? Via some setting? It's extremely annoying to use a lot of libraries (as happens often in Java) and then have to go to the website or local javadoc location to lookup information when you have it in the source jars right there!

标签: java eclipse
17条回答
临风纵饮
3楼-- · 2019-01-01 07:27

It may seem like overkill, but if you use maven and include source, the mvn eclipse plugin will generate all the source configuration needed to give you all the in-line documentation you could ask for.

查看更多
听够珍惜
4楼-- · 2019-01-01 07:28

yes there is a easy way... go to ... http://sourceforge.net/projects/jdk7src/ and download the zip file. Then attach this to the eclipse. Give the path where you have downloaded the zip file in eclipse. We can then browse through the source.

查看更多
春风洒进眼中
5楼-- · 2019-01-01 07:30

1) Hold Control+ left click on the method you want to see. Then Eclipse will bring you to the Source Not Found page.

2) Click on "Attach Source" enter image description here

3) enter image description here

4) Navigate to C:\Program Files\Java\jdk-9.0.1\lib\src.zip

5) Click OK enter image description here Now you should see the source code.

查看更多
孤独寂梦人
6楼-- · 2019-01-01 07:30

Another thought for making that easier when using an automated build:

When you create a jar of one of your projects, also create a source files jar:
project.jar
project-src.jar

Instead of going into the build path options dialog to add a source reference to each jar, try the following: add one source reference through the dialog. Edit your .classpath and using the first jar entry as a template, add the source jar files to each of your other jars.

This way you can use Eclipse's navigation aids to their fullest while still using something more standalone to build your projects.

查看更多
还给你的自由
7楼-- · 2019-01-01 07:31

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.

查看更多
登录 后发表回答