如何将 Java API 文档添加到 Eclipse 中?

发布于 2024-10-10 02:08:45 字数 462 浏览 0 评论 0原文

我已经从 http://www.oracle 下载了 Java API 文档。 com/technetwork/java/javase/downloads/index.html#docs 并据称已使用

窗口->首选项->Java->已安装 JREs->编辑->“选择rt.jar”->Javadoc 地点

该位置已被接受并“验证”就好。然而,在我的一生中,当我将鼠标悬停在某个项目上时(例如在 ArrayList 的声明中),我无法让 Eclipse 在工具提示中显示 Javadocs。我还重新启动了 Eclipse,试图让它正常工作,

我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

铁憨憨 2024-10-17 02:08:45

要在Eclipse中使用离线Java API文档,您需要先下载它。 Java 文档的链接是(最后更新于 2013 年 10 月 21 日):

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

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

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

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

  1. 将 zip 文件解压到本地目录中。
  2. 从 eclipse Window -->偏好设置 --> Java --> “Installed JREs” 选择可用的 JRE(例如 jre6:C:\Program Files (x86)\Java\jre6)并单击“编辑”。
  3. 使用 Control+A 选择所有“JRE 系统库”。
  4. 单击“Javadoc 位置”,
  5. 将“Javadoc 位置路径:”从“http://download”更改为“Javadoc 位置路径:”。 oracle.com/javase/6/docs/api/”到“file:/E:/Java/docs/api/”。

它必须像对我一样有效。我不再需要 Internet 连接来查看 Eclipse 中的 Java API 文档。

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.

忆梦 2024-10-17 02:08:45

用于来自 zip 文件的脱机 Javadoc,而不是提取它。

为什么采用这种方法?

这已经得到解答,它使用提取的 zip 数据,但它比简单的 zip 文件消耗更多的内存。

zip 文件和提取的数据的比较。

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

所以这种方法节省了我的大约。 200MB。

如何使用 apidocs.zip?

1.打开Windows ->首选项

在此处输入图像描述

2.从已安装的JRE中选择jre,然后单击编辑...

在此处输入图像描述

3.从JRE系统库中选择所有.jar文件,然后单击Javadoc Location...

在此处输入图像描述

4.浏览apidocs.zip文件的存档路径并设置存档内的路径,如上所示。就是这样。

5.将光标放在任何类名或方法名上,然后按 Shift + F2

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

逆夏时光 2024-10-17 02:08:45

Eclipse 不会从 javadoc 位置提取工具提示。它仅使用 javadoc 位置添加到链接前面,如果您说在浏览器中打开,则需要下载并附加 JDK 的源代码才能获取工具提示。对于 JRE 下的所有 JAR,您应该具有以下 javadoc 位置: http:// /java.sun.com/javase/6/docs/api/。对于 resources.jar、rt.jar、jsse.jar、jce.jar 和 charsets.jar,您应该附加可用的源

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.

女皇必胜 2024-10-17 02:08:45

老问题,但我目前遇到这个问题。所以我为您提供我的解决方案。
现在源代码和javadoc都在jdk里面了。所以,解压你的jdk版本。你可以看到它包含一个“src.zip”文件。这是您需要的源代码和文档文件。
遵循以下路径:
窗口 -> 首选项 -> Java -> 安装的 JRE ->选择您的 jre/jrd 并按“编辑”
选择所有 .jar 文件,然后按源附件。
选择“外部文件...”按钮,并将其指向 src.zip 文件。

也许需要重新启动 Eclipse。 (通常不会)
现在您应该看到文档以及 jdk 中的类的源代码。

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.

她如夕阳 2024-10-17 02:08:45

我遇到了同样的问题,但我没有发现上面的一些答案有用,因为它们是旧的并且使用新的 JDK 1.8 ,文档部分有
已移至 JDK 文件夹 (C:\Program Files\Java\jdk1.8.0_101 ) 中的 src.zip 。

现在我尝试了上面的所有内容,如果我按 ctrl 并单击程序中的(例如字符串或系统),它会向我显示同样的问题,我会得到未找到源

现在您可以执行此操作,转到安装 JDK (C:\Program Files\Java\jdk1.8.0_101) 的文件夹并尝试解压缩 src.zip。在这里,您可能会遇到一个问题,因为有时由于该文件夹的管理权限,它不允许您解压缩此 src.zip。要解决此问题,请复制 src.zip 并粘贴到任何其他文件夹(例如桌面)中,然后创建一个文件夹 src 并在其中解压缩。
现在将此文件夹复制回 JDK 1.8 文件夹**(C:\Program Files\Java\jdk1.8.0_101)。**

现在只需转到 Eclipse 并打开任何程序,然后按 ctrl 并单击任何外部对象或任何内容(例如例如字符串或系统)。您将得到未找到源,现在单击附加源->外部位置 -> 外部文件夹并添加您的 src 位置 (C:\Program Files\Java\jdk1.8.0_101\src)。
现在你可以走了,我尝试过并且对我有用。

上述所有文件夹位置均来自我的系统,因此对您来说可能会有所不同。

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.

三生路 2024-10-17 02:08:45
  1. 转到您的 JDK 安装。 (C:\Program Files\Java\jdk1.8.0_66 对我来说)。

  2. 解压 src.zip 文件(对我来说变成 C:\Program Files\Java\jdk1.8.0_66\src\)。

  3. 在 Eclipse 编辑器窗口中:CTRL + 单击 java.lang 库类。 (类似于 String)。

  4. Eclipse 会抱怨未找到源并告诉您没有源。

  5. 点击附加源 -> 外部位置 -> 外部文件夹

  6. 找到您的源文件夹(C:\Program Files\Java\jdk1.8.0_66\src\ 对我来说)。

  7. 点击确定 -> 确定

  8. 享受。

  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.

属性 2024-10-17 02:08:45

您在 Javadoc Location 中指定的路径可能有问题。这是相当挑剔的。确保它指向 javadoc 开始的根目录。它可能是您下载的 zip 文件中的几个目录。

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.

笑梦风尘 2024-10-17 02:08:45

我遇到了类似的问题,看起来罪魁祸首是存档路径中的空间(例如,C:\Program Files\java\jdk)。将存档移动到路径中没有空格的另一个目录后,它开始工作。

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.

许久 2024-10-17 02:08:45

不附加 JavaDoc,而是附加 JDK src.zip

在此处输入图像描述

Instead of attaching JavaDoc attach JDK src.zip

enter image description here

傲性难收 2024-10-17 02:08:45

选择一个您想要查看其文档的类,然后按 Ctrl+单击它,Javadoc 页面将通知您没有附加 Javadoc 文件,并且下面将看到一个名为“附加文件”的按钮。按该按钮并浏览到安装 JDK 的目录,通常对于 Win 来说是 C:\Program files\Java\jdk_xxx ,在​​该文件夹内有一个 src.zip 文件 - 选择它并按“确定”,一切就完成了 - 你已经附有 Javadoc。

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.

善良天后 2024-10-17 02:08:45

对于 Linux 上的 OpenJDK 8,请参阅:https://askubuntu.com/questions/755853/how-to -install-jdk-sources

对我有用的方法是:

  • 默认的 src.zip 是指向不存在的文件夹的符号链接...
  • sudo apt- get install openjdk-8-source 这会添加此文件夹
  • 找到“src.zip”
  • Eclipse:Window -->偏好设置 --> Java --> “已安装的 JRE”,编辑并指向 src.zip(或打开任何 JRE 类,例如 HashMap 并附加源)

您现在应该在通过 Ctrl+ 打开 JRE 类时看到 JavaDoc Shift+t,以前这是不可能的,Eclipse 可能已经从默认 URL 获取了关于鼠标悬停方法的文档,但这需要稳定的互联网连接。

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.

春夜浅 2024-10-17 02:08:45

确保“首选项”-> “Java”-> 「编辑器」-> “悬停”->选中“组合悬停”。

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

仅冇旳回忆 2024-10-17 02:08:45

我只需要自己深入研究这个问题就成功了。与其他人提供的解决方案相反,我的幸福结局之路与 JavaDoc 直接相关。不需要“src.zip”文件。我在这个过程中经历的考验和磨难包括寻找正确的JavaDoc来指出。将 Java 1.7 项目指向 Java 8 Javadoc 不起作用。 (即使“jre8”似乎是唯一已安装可用的 JRE。)因此,我不必要地把头撞在砖墙上。

窗口>首选项>爪哇>安装的 JRE

如果您的项目的 JRE 未列出(正如我将 jre7 项目迁移到新的 jre8 工作区时发生的情况),您将需要在此处添加它。单击“添加...”并将工作区指向所需的 jre 文件夹。 (我的是 C://Program Files/Java/jre7)。然后“编辑...”现在可用的 JRE,选择 rt.jar,然后单击“Javadoc Location...”并将其瞄准正确的 javadoc 位置。对于我的使用:

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

瞧,悬停工具提示 javadoc 已重新启用。我希望这可以帮助其他试图解决这个问题的人。

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.

私野 2024-10-17 02:08:45

如果您使用的是 Maven:

mvn eclipse:eclipse -DdownloadSources=true  -DdownloadJavadocs=true

if you are using maven:

mvn eclipse:eclipse -DdownloadSources=true  -DdownloadJavadocs=true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文