在 Mac OS X 上使用 Eclipse 查看 Java 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5239720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Viewing Java documentation with Eclipse on Mac OS X
提问by Ariel
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:
我正在尝试完成一项非常基本的任务,但不知何故似乎无法找到如何... ,就像我几年前在 Windows 上使用 Eclipse 所做的那样,将光标放在类名(例如 PrintWriter)上,然后单击 Ctrl+F2 将打开 PrintWriter 类的 Java 文档。这是我的环境:
- Running OS X version 10.6.6.
- Just downloaded and installed the Java Developer Package for Mac OS X 10.6 Update 4 from connect.apple.com
- I have Eclipse Galileo installed.
- 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?
- 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...
- 运行 OS X 版本 10.6.6。
- 刚刚从 connect.apple.com 下载并安装了适用于 Mac OS X 10.6 Update 4 的 Java Developer Package
- 我安装了 Eclipse Galileo。
- 在/Library/Java/JavaVirtualMachines下,我有一个名为1.6.0_24-b07-334.jdk的文件,它似乎是我刚刚安装的新JDK。但是,它是单个文件,没有扩展为目录和文件。右键单击它并选择“显示包内容”向我显示它的深处包含文件 docs.jar 和 src.jar。但是,不确定我应该如何处理 1.6.0_24-b07-334.jdk 文件 - 我应该保持原样,还是将其扩展为完整的目录结构?
- 在 Eclipse Preferences, Java/Installed JREs 下,我选择了 JVM 1.6.0 (MacOS X Default)。但是,路径指向 /System/Library... 而不是 /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.
无论如何,在 Eclipse 中,将鼠标放在类名上,我会得到一个带有类的简短说明的棕色对话框。但是,我不知道如何打开该类的完整 java 文档。也无法在 Eclipse 中的任何地方找到指示从何处获取 java 文档的位置,也找不到哪个热键可以打开 java 文档。
I apologize for the many details, I'm just assuming they may be necessary to get a good answer.
我为很多细节道歉,我只是假设它们可能是获得好的答案所必需的。
Thanks!
/A
谢谢!
/一种
回答by gutch
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.
我遇到了同样的问题——以前我可以直接在 Eclipse 中访问 Java 文档和源代码,但是在去年 Apple 的一次 Java 更新之后,这种情况就消失了。
My solution was to manually add the source and Javadoc to the JRE definition in Eclipse. Here's how:
我的解决方案是手动将源代码和 Javadoc 添加到 Eclipse 中的 JRE 定义中。就是这样:
- Navigate to Preferences--> Java--> Installed JREs
- Select your preferred JRE and click Edit...
- Select the classes.jarlibrary (should be the first one in the list) and click Javadoc Location...
- Click Javadoc in archive
- Set Archive pathto
/Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar
- Set Path within archiveto
docs/api
- Click OK
- 导航到首选项--> Java-->已安装的 JRE
- 选择您喜欢的 JRE 并单击编辑...
- 选择classes.jar库(应该是列表中的第一个)并单击Javadoc Location...
- 单击存档中的 Javadoc
- 将存档路径设置为
/Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar
- 将存档中的路径设置为
docs/api
- 单击确定
now, optionally, you can set the source code too...
现在,您也可以选择设置源代码...
- With classes.jarstill selected, click Source Attachment...
- Set Location pathto
/Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar
- Click OK
- 随着classes.jar仍然选中,单击源附件...
- 将位置路径设置为
/Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar
- 单击确定
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.6.0_24-b07-334.jdk包其实只是一个文件夹;它被 OS X 视为单个文件,但如果您知道正确的路径,则可以直接访问其内容。如果您不知道进入的路径怎么办?如果你知道这个技巧,你可以从 Eclipse 浏览内容:
- While attaching source code or Javadoc in Eclipse, click on the External File...or External Folder...button etc to bring up a Finder window
- Navigate to your Java JDK folder (usually
/Library/Java/JavaVirtualMachines
) - You should see a list of your JDKs, for example
1.6.0_22-b04-307.jdk
and1.6.0_24-b07-334.jdk
) - Press /on your keyboard to bring up the Go to the folderdialog box
- Delete the /from the dialog box, and start typing the name of JDK you want to navigate. You can press Tabto autocomplete the name if you like.
- Click Go
- You are now browsing the contents of the JDK package; you can now click through to
Contents/Home
etc where you should seeappledocs.jar
,docs.jar
,src.jar
and other goodies.
- 在 Eclipse 中附加源代码或 Javadoc 时,单击外部文件...或外部文件夹...按钮等以显示 Finder 窗口
- 导航到您的 Java JDK 文件夹(通常为
/Library/Java/JavaVirtualMachines
) - 您应该会看到您的 JDK 列表,例如
1.6.0_22-b04-307.jdk
和1.6.0_24-b07-334.jdk
) - 按键盘上的/ 调出转到文件夹对话框
- 从对话框中删除/,然后开始键入要导航的 JDK 名称。如果您愿意,可以按Tab自动完成名称。
- 点击前往
- 您现在正在浏览 JDK 包的内容;您现在可以通过点击
Contents/Home
等,你应该看到appledocs.jar
,docs.jar
,src.jar
和其他东西。
回答by Mark
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.1http://danbim.blogspot.com/2011/01/java-for-mac-os-x-106-update-3-and.html
对于找到此 StackOverflow-Post 而未找到 src.jar 的每个人:Apple 已将其从 SDK 中删除并且默认情况下不提供,但是您可以从 Apple 自己下载它: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)
PS 需要苹果账号(免费注册)
回答by limc
To bring up the Java documentation in Mac, move your mouse to the desired class, then click SHIFT+FN+F2
.
要在 Mac 中调出 Java 文档,请将鼠标移至所需的类,然后单击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:-
顺便说一下,您可以从Preferences-> General-> Keys-> 输入“ Open Attached Javadoc”找到快捷键。这是我的截图:-
回答by Pa?lo Ebermann
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?
在/Library/Java/JavaVirtualMachines下,我有一个名为1.6.0_24-b07-334.jdk的文件,它似乎是我刚刚安装的新JDK。但是,它是单个文件,没有扩展为目录和文件。右键单击它并选择“显示包内容”向我显示它的深处包含文件 docs.jar 和 src.jar。但是,不确定我应该如何处理 1.6.0_24-b07-334.jdk 文件 - 我应该保持原样,还是将其扩展为完整的目录结构?
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.
从我对 Mac OS 的记忆(两年前我不得不使用它几个月)我认为这不是一个真正的“单个文件”,它只是在文件管理器应用程序中看起来如此。看看您是否可以在 eclipse 的文件选择器对话框中在其中导航,您可以在其中为您的文档选择 docs.jar。
回答by Tao Starbow
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.
我遇到了类似的问题,并且无法访问 Apple Developer 页面以下载 docs.jar 的本地副本。我转到 Preferences > Java > Installed JREs > Edit,然后查看 jars 的“Javadoc Location...”值。Javadoc URI 仍设置为“ http://java.sun.com/javase/6/docs/api/”。当我将其更改为“ http://docs.oracle.com/javase/6/docs/api/”时,工具提示又开始出现。当然,这仅在您在线时才有效。