如何在 Eclipse 中使用 Java 8 文档

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22642230/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:02:13  来源:igfitidea点击:

How to use Java 8 docs in Eclipse

javaeclipsejava-8

提问by rosscarrothers

I'm having issues seeing API documentation for Java 8 in Eclipse. Here's an example of the problem I'm having

我在 Eclipse 中查看 Java 8 的 API 文档时遇到问题。这是我遇到的问题的示例

Calendar myCalendar = Calendar.getInstance();

If I mouse over Calendarthen I see all the correct documentation, however if I mouse over getInstance()I get a message saying

如果我将鼠标悬停在上面,Calendar我会看到所有正确的文档,但是如果我将鼠标悬停在上面,getInstance()我会收到一条消息说

Note: This element has no attached source and the Javadoc could not be found in the attached Javadoc.

注意:此元素没有附加的源代码,并且在附加的 Javadoc 中找不到 Javadoc。

I have the Javadoc location for rt.jar set to http://docs.oracle.com/javase/8/docs/api/, I've also tried downloading a local copy of the docs and had the same problem. Changing the link to the Java 7 docs fixes the problem I'm having.

我将 rt.jar 的 Javadoc 位置设置为http://docs.oracle.com/javase/8/docs/api/,我也尝试下载文档的本地副本并遇到了同样的问题。更改指向 Java 7 文档的链接解决了我遇到的问题。

Eclipse seems to be using the wrong anchor style (not sure how else to word it) when looking for methods. When it looks for the getInstance()method, it checks http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getInstance(), but it should be checking

在寻找方法时,Eclipse 似乎使用了错误的锚点样式(不知道如何表达)。当它寻找getInstance()方法时,它会检查http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getInstance(),但它应该检查

Calendar.html#getInstance--

Calendar.html#getInstance--

All brackets and commas seem to have been replaced by hyphens in the Java 8 doc links. I experienced this problem with Eclipse 4.3 (Kepler), 4.3 with the patches for Java 8, and now with 4.4 (Luna)

Java 8 文档链接中的所有括号和逗号似乎都已被连字符替换。我在 Eclipse 4.3 (Kepler)、带有 Java 8 补丁的 4.3 和现在 4.4 (Luna) 中遇到了这个问题

Is there a way to update Eclipse so that it properly displays the docs in the mouse over tooltips?

有没有办法更新 Eclipse,以便它在工具提示上的鼠标中正确显示文档?

采纳答案by Jigar Joshi

Setting the installed JRE to JDK 8 fixes your problem.

将已安装的 JRE 设置为 JDK 8 可以解决您的问题。

This can be done by going to

这可以通过去完成

Window -> Preferences -> Java -> Installed JRE -> Edit -> Directory and selecting the JDK 8 installation folder

回答by user3569741

I had the same problem. I did set the installed JRE to be JDK8. Still wasn't working until I clicked "edit" on the jre (under 'Installed JREs') then then clicked "Restore Defaults". Then it started working... Looking at each jar in that list I see it sets "Source attachement" and not "Javadoc location". Seems to work.

我有同样的问题。我确实将安装的 JRE 设置为 JDK8。直到我单击 jre 上的“编辑”(在“已安装的 JRE”下)然后单击“恢复默认值”后,仍然无法正常工作。然后它开始工作......查看该列表中的每个 jar,我看到它设置了“源附件”而不是“Javadoc 位置”。似乎工作。

回答by Prateek

Step 1: Windows -> Preference -> Java -> Installed JRE -> Edit -> Directory (Specify the JDK directory (and not JRE))

步骤 1:Windows -> Preference -> Java -> Installed JRE -> Edit -> Directory(指定 JDK 目录(而不是 JRE))

Step 2: Click "Restore Defaults"

第二步:点击“恢复默认设置”

Step 3: Click OK

第三步:点击确定

回答by Casey Murray

This worked for me in Ubuntu 14.10, Eclipse Kepler using openjdk-8

这在 Ubuntu 14.10 中对我有用,Eclipse Kepler 使用 openjdk-8

Window > Preferences > Java > Installed JREs > Click on your java-8-openjdk > Edit

窗口 > 首选项 > Java > 已安装的 JRE > 单击您的 java-8-openjdk > 编辑

For /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:

对于 /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:

set Source attachment to:

将源附件设置为:

/usr/lib/jvm/java-8-openjdk-amd64/src.zip

set Javadoc location to:

将 Javadoc 位置设置为:

file:/usr/share/doc/openjdk-8-doc/api/

NOTE: If you don't already have the openjdk-8 java doc, install:

注意:如果您还没有 openjdk-8 java doc,请安装:

sudo apt-get install openjdk-8-doc

and for the source:

和来源:

sudo apt-get install openjdk-8-source