14

Up to a few days ago, Eclipse was working fine in locating the javadoc for base classes such as Java.io.File. Recently, though, hovering over these classes only yields a message indicating that the source and javadoc are missing:

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

I couldn't for the life of me locate the option that would let me reselect the location of the basic documentation. Does anyone know how to fix this?

akrolsmir
  • 312
  • 1
  • 4
  • 14

5 Answers5

13

I encountered this problem now a couple of times too. It's especially annoying if you have a lot of projects in your workspace and you don't want to set the javadoc locations for each project.

Referencing the online documentation works well indeed, and there is a way to do that globally for all Java libraries:

  • Go to: Window -> Preferences
  • Expand: Java -> Installed JREs
  • Select your default Java installation
  • Press ''Edit''
  • Select all the JRE system libraries
  • Press ''Javadoc Location...''
  • In the Javadoc location path put in the path to the online documentation. For Java 8 for example this is http://docs.oracle.com/javase/8/docs/api/. (If you press ''Validate...'' it will tell you if it is a valid javadoc location.)
  • Press ''OK'', then ''Finish'', then ''OK''

And here you have some images:

Eclipse Settings: Installed JREs

Select all JRE system libraries

Edit javadoc location

And your basic Java javadoc is ready to go.

Terry
  • 14,529
  • 13
  • 63
  • 88
  • I used this method and hit validate which passed. I then restarted Eclipse and still don't have any JavaDoc showing up. Additionally, I can successfully query http://docs.oracle.com/javase/7/docs/api/ from a browser. This is for Open JDK 7 on Ubuntu 14.04. – fIwJlxSzApHEZIl Nov 18 '14 at 02:41
  • 1
    Worth noting that the docs.oracle.com/javase/11/docs/api URL is not valid, which is the address Eclipse predicts for JDK11. That's why it wasn't working for me. Luckily I'm using a JDK8 execution environment and can use the JDK8 docs instead of JDK11 docs. – Kelly Bang Jul 08 '19 at 17:56
  • 1
    You saved me, and for jdk 15 the valid url i used is ```https://docs.oracle.com/en/java/javase/15/docs/api/``` – Lorenzo Nov 19 '20 at 15:08
12

The best way to do it is Go to Project > Properties > Java Build Path > Libraries and expand JRE System Library [your jre version] then, rt.jar. Select Source attachment, click Edit…. Select the source code file (External File…) and press OK.

Other ways to attach java source code is mentioned in this link

http://www.cavdar.net/2008/07/14/3-ways-of-jdk-source-code-attachment-in-eclipse/

AurA
  • 12,135
  • 7
  • 46
  • 63
  • This solution works well for when you don't have an internet connection. – Aaron Jun 11 '14 at 19:02
  • My rt.jar is already pointing to http://docs.oracle.com/javase/7/docs/api/ but I don't have any standard JDK documentation loading in Eclipse. – fIwJlxSzApHEZIl Nov 18 '14 at 02:31
  • I should select `Javadoc Location` at `jrt-fs.jar`, and set `https://docs.oracle.com/javase/7/docs/api/`. This finally works for "Eclipse Oxygen.2" and "JavaSE-9 (jre-9.0.4)" – Brethlosze Mar 09 '18 at 20:25
12

Expand your JRE System library and find rt.jar (classes.jar for Mac OS X). Right click, and select 'Properties'.

classes.jar

You can then specify the Javadoc location (as well as the source location).

properties

Greg Kopff
  • 15,945
  • 12
  • 55
  • 78
  • Best answer for the helpful graphics =) – akrolsmir Apr 04 '12 at 04:21
  • The helpful graphics confused me because it made me skim over the words and the fact that it is `rt` on windows. An edit to the image with the text "rt.jar on windows" would be nice – Old Badman Grey Nov 11 '14 at 19:18
  • I don't have a classes.jar entry under my JRE System Library Entry. Java SE 1.7 Ubuntu 14.04 Eclipse 4.4.1 OpenJDK 7 Additionally, all my other JARs are already pointing to http://docs.oracle.com/javase/7/docs/api/ including rt.jar – fIwJlxSzApHEZIl Nov 18 '14 at 02:31
  • I already have a Javadoc location in my properties, but it doesn't find the Javadoc for any of the library objects that I use! This happens to me on Arch Linux, but on Windows, no such problem. – ViceroyFaust Jan 18 '20 at 21:24
4

Press ctrl+click (or command+click if you're on a Mac) on any method which doesn't have javadocs. For example, in this line:

System.out.println();

... assuming that no javadocs are available for println, control-clicking on println will open a new tab with a button labeled "Attach Source...". And that's it!

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • 2
    Kudos for an extremely quick and easy solution. – akrolsmir Apr 04 '12 at 04:20
  • This method is asking to attach java doc source at the project level. but the JDK should have documentation at the global level for every single project. otherwise this will be a pain having to do it for every project. – fIwJlxSzApHEZIl Nov 18 '14 at 02:36
2

I had the same problem.

I uninstalled eclipse, removed all eclipse specific data from my user's home- and application data directory, uninstalled all Java JREs and JDKs but nothing helped.

The solution on my system was to change the protocol in the JavaDoc URL from HTTP to HTTPS

e.g. for JRE 7 i changed the URL from http://docs.oracle.com/javase/7/docs/api/ to https://docs.oracle.com/javase/7/docs/api/

(use the steps mentioned by Terry and replace the 'http' with 'https')

tom redfern
  • 30,562
  • 14
  • 91
  • 126
Markus
  • 61
  • 6
  • Upvoted you, as Eclipse should default to the correct URL for standard libraries, and this is effectively a way to make it work if you are on a machine that blocks non HTTPS traffic. Though it might be best to move this to a comment on @Terry 's answer. – Didier A. Jun 13 '16 at 21:46
  • This worked for me except it was the other way around. Mine was set to HTTPS and kept saying that was invalid when I'd click "Validate" and then I changed it to HTTP and it worked. – Tim Feb 13 '17 at 17:08