Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing Java documentation with Eclipse on Mac OS X

I'm trying to accomplish a very basic task and somehow can't seem to find how... I would like to have my Eclipse environment set in a way that I can get help and documentation on any standard class/method in the JDK, like I used to do a few years ago with Eclipse on Windows, where having the cursor on a class name (e.g. PrintWriter), and clicking Ctrl+F2 would open up the Java documentation for the PrintWriter class. Here's my environment:

  1. Running OS X version 10.6.6.
  2. Just downloaded and installed the Java Developer Package for Mac OS X 10.6 Update 4 from connect.apple.com
  3. I have Eclipse Galileo installed.
  4. Under /Library/Java/JavaVirtualMachines I have a file named 1.6.0_24-b07-334.jdk, which seems to be the new JDK I just installed. However, it's a single file, not expanded into directories and files. Right-clicking it and selecting "Show Package Content" shows me that deep inside it contains the files docs.jar and src.jar. However, not sure what I should be doing with the 1.6.0_24-b07-334.jdk file - should I leave it as is, or perhaps expand it to a full directory structure?
  5. Under Eclipse Preferences, Java/Installed JREs I have JVM 1.6.0 (MacOS X Default) selected. However, the path points to /System/Library... and not to /Library...

Anyway, in Eclipse, putting the mouse over a class name, I get a brown dialog with a short explanation of the class. However, I don't know how to open up the full java documentation of the class. Also couldn't find anywhere in Eclipse a place to indicate where to take the java documentation from, nor which hotkey would bring the java documentation up.

I apologize for the many details, I'm just assuming they may be necessary to get a good answer.

Thanks!
/A

like image 869
Ariel Avatar asked Mar 08 '11 23:03

Ariel


1 Answers

I've had the same problem — previously I had been able access Java documentation and source directly in Eclipse, but that disappeared after one of the Java updates from Apple last year.

My solution was to manually add the source and Javadoc to the JRE definition in Eclipse. Here's how:

  1. Navigate to Preferences --> Java --> Installed JREs
  2. Select your preferred JRE and click Edit...
  3. Select the classes.jar library (should be the first one in the list) and click Javadoc Location...
  4. Click Javadoc in archive
  5. Set Archive path to /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar
  6. Set Path within archive to docs/api
  7. Click OK

now, optionally, you can set the source code too...

  1. With classes.jar still selected, click Source Attachment...
  2. Set Location path to /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar
  3. Click OK

In fact that 1.6.0_24-b07-334.jdk package is actually just a folder; it is treated as a single file by OS X but you can access its contents directly if you know the right path. What if you don't know what path the enter? You can browse the contents from Eclipse if you know this trick:

  1. While attaching source code or Javadoc in Eclipse, click on the External File... or External Folder... button etc to bring up a Finder window
  2. Navigate to your Java JDK folder (usually /Library/Java/JavaVirtualMachines)
  3. You should see a list of your JDKs, for example 1.6.0_22-b04-307.jdk and 1.6.0_24-b07-334.jdk)
  4. Press / on your keyboard to bring up the Go to the folder dialog box
  5. Delete the / from the dialog box, and start typing the name of JDK you want to navigate. You can press Tab to autocomplete the name if you like.
  6. Click Go
  7. You are now browsing the contents of the JDK package; you can now click through to Contents/Home etc where you should see appledocs.jar, docs.jar, src.jar and other goodies.
like image 80
gutch Avatar answered Sep 21 '22 03:09

gutch