简体   繁体   中英

How to use Java 8 docs in Eclipse

I'm having issues seeing API documentation for Java 8 in Eclipse. Here's an example of the problem I'm having

Calendar myCalendar = Calendar.getInstance();

If I mouse over Calendar then I see all the correct documentation, however if I mouse over getInstance() I get a message saying

Note: This element has no attached source and the Javadoc could not be found in the attached Javadoc.

I have the Javadoc location for rt.jar set to http://docs.oracle.com/javase/8/docs/api/ , I've also tried downloading a local copy of the docs and had the same problem. Changing the link to the Java 7 docs fixes the problem I'm having.

Eclipse seems to be using the wrong anchor style (not sure how else to word it) when looking for methods. When it looks for the getInstance() method, it checks http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getInstance() , but it should be checking

Calendar.html#getInstance--

All brackets and commas seem to have been replaced by hyphens in the Java 8 doc links. I experienced this problem with Eclipse 4.3 (Kepler), 4.3 with the patches for Java 8, and now with 4.4 (Luna)

Is there a way to update Eclipse so that it properly displays the docs in the mouse over tooltips?

Setting the installed JRE to JDK 8 fixes your problem.

This can be done by going to

Window -> Preferences -> Java -> Installed JRE -> Edit -> Directory and selecting the JDK 8 installation folder

Step 1: Windows -> Preference -> Java -> Installed JRE -> Edit -> Directory (Specify the JDK directory (and not JRE))

Step 2: Click "Restore Defaults"

Step 3: Click OK

This worked for me in Ubuntu 14.10, Eclipse Kepler using openjdk-8

Window > Preferences > Java > Installed JREs > Click on your java-8-openjdk > Edit

For /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:

set Source attachment to:

/usr/lib/jvm/java-8-openjdk-amd64/src.zip

set Javadoc location to:

file:/usr/share/doc/openjdk-8-doc/api/

NOTE: If you don't already have the openjdk-8 java doc, install:

sudo apt-get install openjdk-8-doc

and for the source:

sudo apt-get install openjdk-8-source

I had the same problem. I did set the installed JRE to be JDK8. Still wasn't working until I clicked "edit" on the jre (under 'Installed JREs') then then clicked "Restore Defaults". Then it started working... Looking at each jar in that list I see it sets "Source attachement" and not "Javadoc location". Seems to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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