开发者

Viewing Java documentation with Eclipse on Mac OS X

I'm trying to accompl开发者_StackOverflow中文版ish 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


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.


For everyone finding this StackOverflow-Post and not finding the src.jar: Apple removed it from the SDK and it's not supplied by default, however you can download it from Apple self at: http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1.3.3.1.0.1.1.0.3.9.3.3.1 http://danbim.blogspot.com/2011/01/java-for-mac-os-x-106-update-3-and.html

P.S. Apple account is required (free registration)


To bring up the Java documentation in Mac, move your mouse to the desired class, then click SHIFT+FN+F2.

By the way, you can find out the shortcut key from Preferences -> General -> Keys -> type "Open Attached Javadoc". Here's my screenshot:-

Viewing Java documentation with Eclipse on Mac OS X


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?

From what I remember from Mac OS (I had to use one two years ago for some months) I think this is not really a "single file", it only looks so in the file manager application. Look if you can navigate inside it in the file-chooser dialog of eclipse where you can select the docs.jar for your documentation.


I was having a similar problem, and was having trouble accessing the Apple Developer page to download a local copy of the docs.jar. I went to Preferences > Java > Installed JREs > Edit, and then looked at the "Javadoc Location..." value for the jars. The Javadoc URI was still set to "http://java.sun.com/javase/6/docs/api/". When I changed it to "http://docs.oracle.com/javase/6/docs/api/" the tooltips started showing up again. Of course, this will only work when you are online.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜