64

I have downloaded Java API documentation from http://www.oracle.com/technetwork/java/javase/downloads/index.html#docs and have supposedly attached it to Eclipse using the

Window->Preferences->Java->Installed JREs->Edit->"Select rt.jar"->Javadoc Location

And the location has been accepted and "Validates" just fine. However, for the life of me, I can't get Eclipse to show the Javadocs in the tooltip whene I hover over an item (for example in the declaration of an ArrayList). I have also restarted Eclipse in attempts to get it to work

What am I doing wrong?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Kurru
  • 14,180
  • 18
  • 64
  • 84
  • 1
    Ah. Didn't realise this at the time, since I'm developing an Android application I don't seem to use the JRE jar files, instead use an Android jar file :-/ I attached the java api doc to this file and the tooltip started working. Thanks for your help – Kurru Jan 05 '11 at 23:33
  • 2
    Follow steps in [this](http://coding9.blogspot.com/2012/12/how-to-add-javadoc-offline-in-eclipse.html?showComment=1396171343302#c1705406766233784620) link, it worked for me. – Amr Lotfy Mar 30 '14 at 09:34
  • also it should be noted that when you press F3 on a Java class from the API it will try to open the source not the Javadoc, normally you won't need to look at the source code for a native Java library and can instead mouse over and click the bottom icon in the tooltip that directs you to "open attached Javadoc in browser" this will load your local Javadoc if you follow the directions in the following answer. – JesseBoyd Sep 02 '17 at 20:47
  • For JDK 10 you can follow below step: https://stackoverflow.com/questions/51952111/how-can-i-view-java-10-javadocs-in-eclipse/52881855#52881855 – Amir Oct 18 '18 at 22:33

14 Answers14

107

To use offline Java API Documentation in Eclipse, you need to download it first. The link for Java docs are (last updated on 2013-10-21):

Java 6
Page: http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-doc-download-355137.html
Direct: http://download.oracle.com/otn-pub/java/jdk/6u30-b12/jdk-6u30-apidocs.zip

Java 7
Page: http://www.oracle.com/technetwork/java/javase/documentation/java-se-7-doc-download-435117.html

Java 8
Page: http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downloads-2133158.html

Java 9
Page:http://www.oracle.com/technetwork/java/javase/documentation/jdk9-doc-downloads-3850606.html

  1. Extract the zip file in your local directory.
  2. From eclipse Window --> Preferences --> Java --> "Installed JREs" select available JRE (jre6: C:\Program Files (x86)\Java\jre6 for instance) and click Edit.
  3. Select all the "JRE System libraries" using Control+A.
  4. Click "Javadoc Location"
  5. Change "Javadoc location path:" from "http://download.oracle.com/javase/6/docs/api/" to "file:/E:/Java/docs/api/".

It must work as it works for me. I don't need Internet connection to view Java API Documentation in Eclipse anymore.

Seagull
  • 1,063
  • 1
  • 11
  • 18
cslraju
  • 1,071
  • 2
  • 7
  • 4
57

For offline Javadoc from zip file rather than extracting it.

Why this approach?

This is already answered which uses extracted zip data but it consumes more memory than simple zip file.

Comparison of zip file and extracted data.

jdk-6u25-fcs-bin-b04-apidocs.zip  --->  ~57 MB
after extracting this zip file  --->  ~264 MB !

So this approach saves my approx. 200 MB.

How to use apidocs.zip?

1.Open Windows -> Preferences

enter image description here

2.Select jre from Installed JREs then Click Edit...

enter image description here

3.Select all .jar files from JRE system libraries then Click Javadoc Location...

enter image description here

4.Browse for apidocs.zip file for Archive path and set Path within archive as shown above. That's it.

5.Put cursor on any class name or method name and hit Shift + F2

Community
  • 1
  • 1
Rahul Virpara
  • 1,209
  • 1
  • 12
  • 24
26

Eclipse doesn't pull the tooltips from the javadoc location. It only uses the javadoc location to prepend to the link if you say open in browser, you need to download and attach the source for the JDK in order to get the tooltips. For all the JARs under the JRE you should have the following for the javadoc location: http://java.sun.com/javase/6/docs/api/. For resources.jar, rt.jar, jsse.jar, jce.jar and charsets.jar you should attach the source available here.

LINEMAN78
  • 2,562
  • 16
  • 19
  • I downloaded that jar and attached it as source for all those jars, but the tool tips and the javadoc viewer both still aren't showing the details – Kurru Jan 05 '11 at 02:41
  • 1
    Is the JRE you are modifying the default? Also is it the JRE selected for the project(right click on the project and go to preferences)? If so can you press F3 while highlighting a JRE class and pull up the source? – LINEMAN78 Jan 05 '11 at 10:00
  • Is that still correct? I have a current workspace where no source code is attached, only javadoc, and it shows the tooltips just fine. – kutschkem Jan 15 '18 at 13:39
12

Old question, but I had current problems with this issue. So I provide you my solution. Now the sources and javadocs are inside the jdk. So, unzip your jdk version.You can see that contanins a "src.zip" file. Here are your needed sources and doc files. Follow the path: Window->Preferences->Java->Installed JREs-> select your jre/jrd and press "Edit" Select all .jar files, and press Source Attachement. Select the "External File..." button, and point it to src.zip file.

Maibe a restart to Eclipse is needed. (normally not) Now you should see the docs, and also the sources for the classes from jdk.

Tudor Jescu
  • 121
  • 1
  • 2
  • I think this solves the problem correctly, cause I didn't see any "Javadoc" or apidocs.zip in the JDK folder. The src.zip isn't a Javadoc but the sources - and your answer solve my problem, Thanks! – Shukant Pal Jul 08 '18 at 15:52
6

I went through the same problem and I did not find some of the above answer useful because they are old and with new JDK 1.8 , documentation section has been moved to src.zip in JDK folder (C:\Program Files\Java\jdk1.8.0_101 ) .

Now I tried everything from above and it was showing me the same problem if I press ctrl and click on (for example String or System) in my program I get the Source not found.

Now you can do this, go to the folder where JDK (C:\Program Files\Java\jdk1.8.0_101) is installed and try to unzip src.zip. Here you might face an issue as sometime due to administrative rights on this folder it would not allow you to unzip this src.zip. For solving the issue , copy src.zip and paste in any other folder ( example Desktop) and then create a folder src and unzip in it. Now copy this folder back to JDK 1.8 folder**(C:\Program Files\Java\jdk1.8.0_101).**

Now just go to eclipse and open any program and press ctrl and click on any external objects or anything (for example String or System) .You will get Source not found , Now Click Attach source -> External Location -> External Folder and add your src location (C:\Program Files\Java\jdk1.8.0_101\src). Now you are good to go , I tried and it worked for me.

All the above folder location are from my system , so It might be different for you.

PRAVEEN SONI
  • 71
  • 1
  • 1
4
  1. Go to your JDK installation. (C:\Program Files\Java\jdk1.8.0_66 for me).

  2. Unzip the src.zip file (becomes C:\Program Files\Java\jdk1.8.0_66\src\ for me).

  3. In the Eclipse editor window: CTRL + Click on a java.lang library class. (something like String).

  4. Eclipse will complain Source not found and tell you that you don't have the source.

  5. Click Attach source -> External Location -> External Folder.

  6. Find your source folder (C:\Program Files\Java\jdk1.8.0_66\src\ for me).

  7. Click OK -> OK.

  8. Enjoy.

Lucho
  • 71
  • 4
1

Likely a problem with the path that you specified in Javadoc Location. It is pretty finicky. Make sure that it points at the root of where the javadoc starts. It could be a few directories down in the zip you've downloaded.

Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61
1

Instead of attaching JavaDoc attach JDK src.zip

enter image description here

Amit Yadav
  • 32,664
  • 6
  • 42
  • 57
1

Choose one class you want to view its documentation and press Ctrl+click over it, the Javadoc page will inform you that there is no Javadoc file attached and bellow will see a button named "Attach File". Press that button and browse to the directory where JDK is installed, normally for Win is C:\Program files\Java\jdk_xxx and inside this folder there is a src.zip file - sleect it and press OK and all is done - you already have Javadoc attached.

1

For OpenJDK 8 on Linux see: https://askubuntu.com/questions/755853/how-to-install-jdk-sources

The way that worked for me is:

  • The default src.zip is a symbolic link pointing to a non-existing folder ...
  • sudo apt-get install openjdk-8-source this adds this folder
  • locate "src.zip"
  • Eclipse: Window --> Preferences --> Java --> "Installed JREs", edit and point to src.zip (or open any JRE class like for example HashMap and attach source)

You should now see the JavaDoc when opening JRE classes via Ctrl+Shift+t, previously this was not possible, Eclipse may have got a docs from the default URL on mouse over methods but this requires a stable internet connection.

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
1

I have had a similar issue and looks like that the culprit was the space in the path to the archive (e.g., C:\Program Files\java\jdk). After moving the archive to another directory without spaces in path it started to work.

apatian
  • 21
  • 1
  • You are right! As mostly Java is installed by default in Program Files directory. One solution is replacing "Program Files" with "Progra~1" in javadocs location. – supernova Jul 28 '13 at 00:55
0

I just had to dig through this issue myself and succeeded. Contrary to what others have offered as solutions, the path to my happy ending was directly correlated to JavaDoc. No "src.zip" files necessary. My trials and tribulations in the process involved finding the CORRECT JavaDoc to point at. Pointing a Java 1.7 project at Java 8 Javadoc does NOT work. (Even if "jre8" appears to be the only installed JRE available.) Thus, I beat my head against the brick wall unnecessarily.

Window > Preferences > Java > Installed JREs

If the JRE of your project is not listed (as happened to me when I migrated a jre7 project to a new jre8 workspace), you will need to add it here. Click "Add..." and point your Workspace at the desired jre folder. (Mine was C://Program Files/Java/jre7). Then "Edit..." the now-available JRE, select the rt.jar, and click "Javadoc Location..." and aim it at the correct javadoc location. For my use:

For jre7 -- http://docs.oracle.com/javase/7/docs/api/ For jre8 -- http://docs.oracle.com/javase/8/docs/api/

Voila, hover tooltip javadoc is re-enabled. I hope this helps anyone else trying to figure this problem out.

Fred Brim
  • 1
  • 1
0

if you are using maven:

mvn eclipse:eclipse -DdownloadSources=true  -DdownloadJavadocs=true
tbo47
  • 2,688
  • 3
  • 20
  • 11
0

Ensure "Preferences" -> "Java" -> "Editor" -> "Hovers" -> "Combined Hover" is checked.

卢声远 Shengyuan Lu
  • 31,208
  • 22
  • 85
  • 130