简体   繁体   English

如何在 Eclipse 中为任何 jar 文件(例如 JavaFX)附加源代码或 JavaDoc?

[英]How to attach source or JavaDoc in eclipse for any jar file e.g. JavaFX?

Presently I'm working with JavaFX.目前我正在使用 JavaFX。 Whenever I hover over a method of JavaFX its gives me the following error:每当我将鼠标悬停在 JavaFX 的方法上时,它都会给我以下错误:

'Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found'

How should I resolve this?我应该如何解决这个问题? How can I attach the javadoc or source so that I could see the description of the methods?如何附加 javadoc 或源代码以便我可以看到方法的描述?

  1. Download jar file containing the JavaDocs.下载包含 JavaDocs 的 jar 文件。
  2. Open the Build Path page of the project (right click, properties , Java build path ).打开项目的Build Path页面(右键单击, propertiesJava build path )。
  3. Open the Libraries tab.打开选项卡。
  4. Expand the node of the library in question (JavaFX).展开相关库的节点 (JavaFX)。
  5. Select JavaDoc location and click edit .选择JavaDoc 位置并单击编辑
  6. Enter the location to the file which contains the Javadoc (the one you just downloaded).输入包含 Javadoc 的文件的位置(您刚刚下载的那个)。

You can configure the Javadocs with downloading jar, basically javadocs will be referred directly from internet.您可以通过下载 jar 来配置 Javadocs,基本上 javadocs 将直接从互联网上引用。

Complete steps:完成步骤:

  1. Open the Build Path page of the project (right click, properties, Java build path).打开项目的Build Path页面(右键,属性,Java构建路径)。
  2. Open the Libraries tab.打开库选项卡。
  3. Expand the node of the library in question (JavaFX).展开相关库的节点 (JavaFX)。
  4. Select JavaDoc location and click edit.选择 JavaDoc 位置并单击编辑。
  5. Enter the location to the file which contains the Javadoc.输入包含 Javadoc 的文件的位置。 Specifically for the javaFX javadoc enter http://docs.oracle.com/javafx/2.0/api/专为 javaFX javadoc 输入http://docs.oracle.com/javafx/2.0/api/

for offline javadocs, you can download from : http://www.oracle.com/technetwork/java/javase/documentation/java-se-7-doc-download-435117.html对于离线 javadoc,您可以从以下位置下载: http : //www.oracle.com/technetwork/java/javase/documentation/java-se-7-doc-download-435117.html

After clicking Accept License Agreement you can download javafx-2_2_0-apidocs.zip单击接受许可协议后,您可以下载javafx-2_2_0-apidocs.zip

Neither Project/Properties/Javadoc Location nor Project/Properties/Java Build Path/Libraries had not helped me until I picked and moved up in " Order and Export " tab of " Java Build Path " "Android Dependencies" and added-in-library.jar. Project/Properties/Javadoc LocationProject/Properties/Java Build Path/Libraries都没有帮助我,直到我在“ Java Build Path ”“Android Dependencies”的“ Order and Export ”选项卡中移动并添加到库中。罐。 I hope it will be useful.我希望它会很有用。

Alternatively you can also,或者你也可以,

1) Navigate to that method by Ctrl+Click on the method. 1) 通过 Ctrl+单击方法导航到该方法。 The new tab/window will opened with text "Source not found" and button "Attach Source.." in it新选项卡/窗口将打开,其中包含文本“未找到源”和按钮“附加源..”
2) Click the button "Attach Source.." 2) 单击“附加源..”按钮
3) New window pops up. 3) 弹出新窗口。 Click the button "External Folder"单击“外部文件夹”按钮
4) Locate the JavaFX javadoc folder. 4) 找到 JavaFX javadoc 文件夹。 If you are on Windows with default installation settings, then the folder path is C:\\Program Files\\Oracle\\JavaFX 2.0 SDK\\docs如果您在 Windows 上使用默认安装设置,则文件夹路径为C:\\Program Files\\Oracle\\JavaFX 2.0 SDK\\docs

First, if you get the message首先,如果您收到消息

Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found注意:此元素既没有附加源也没有附加 Javadoc,因此找不到 Javadoc

Then it means that you've already included the external jar needed for your project.那么这意味着您已经包含了项目所需的外部 jar。

The next step would be to associate the external jar with its javadoc url.下一步是将外部 jar 与其 javadoc url 相关联。

  • go to package explorer, expand your project folder, expand referenced libraries转到包资源管理器,展开您的项目文件夹,展开引用的库
  • right click the external jar that you want to associate its javadoc with右键单击要与其 javadoc 关联的外部 jar
  • click properties -> javadoc location单击属性-> javadoc 位置
  • copy and past the url for the javadoc that you googled online into the javadoc location path将您在线搜索的 javadoc 的 url 复制并粘贴到 javadoc 位置路径中
  • click apply点击申请

And you're all set!你已经准备好了!

Above all answers are right but there is another method also which is very handy.最重要的是答案是正确的,但还有另一种方法也非常方便。

Pre-condition: Your project is Maven project Or converts it to Maven project.前置条件:你的项目是Maven项目或者转换为Maven项目。

RightclickOnProject > Configuration > Convert in to Maven Project RightclickOnProject > 配置 > 转换为 Maven 项目

在此处输入图片说明 - Now follow the steps: - 现在按照以下步骤操作:

1 . 1 . Select any jar for which you want to download sources or javadocs.选择要为其下载源代码或 javadoc 的任何 jar。

2 . 2 . RightClick > Maven > Download javadoc or Download javasources右键单击 > Maven > 下载 javadoc 或下载 javasources

在此处输入图片说明

I couldn't get the "Attach source..." method to work either, and I tried many different ways.我也无法使用“附加源...”方法,我尝试了许多不同的方法。 The Javadocs for JavaFX are installed in Program Files\\Oracle\\JavaFX 2.x SDK\\docs. JavaFX 的 Javadocs 安装在 Program Files\\Oracle\\JavaFX 2.x SDK\\docs 中。 Another way to install the Javadocs is:安装 Javadocs 的另一种方法是:

  1. Right click on the project, select Properties右键单击项目,选择属性
  2. Select Libraries on the right side of the tab选择选项卡右侧的库
  3. At the right top side of the tab, you may see "Default JavaFX Platform" or something similar.在选项卡的右上角,您可能会看到“默认 JavaFX 平台”或类似内容。 Click on the Manage Platforms button.单击管理平台按钮。 (You can also install this default platform from here if you haven't got this already). (如果你还没有安装这个默认平台,你也可以从这里安装)。
  4. In the Java Platform Manager tab which appears, select "Default JavaFX Platform" on the left side, and then click on the JavaFX tab on the right side of the window.在出现的 Java Platform Manager 选项卡中,选择左侧的“Default JavaFX Platform”,然后单击窗口右侧的 JavaFX 选项卡。
  5. One of the entry fields is labeled "JavaFX Javadoc".其中一个条目字段标记为“JavaFX Javadoc”。 Click the "Browse" button next to this field and browse to the installed docs file mentioned above.单击此字段旁边的“浏览”按钮并浏览到上述已安装的文档文件。

Hope this helps some people who were as puzzled as I was.希望这能帮助一些和我一样困惑的人。

In addition to the answer of @dhroove (would have written a comment if I had 50 rep...)除了@dhroove 的回答(如果我有 50 个代表,我会写评论......)

The link has changed to: http://docs.oracle.com/javafx/2/api/链接已更改为: http : //docs.oracle.com/javafx/2/api/

At least my eclipse wasn't able to use the link from him.至少我的日食无法使用他的链接。

It already in a different thread, just a simple eclipse setting will automatically download JavaDoc (but, you need to click the method for first time).它已经在一个不同的线程中,只需一个简单的 eclipse 设置就会自动下载 JavaDoc(但是,您需要第一次单击该方法)。

Where can I download the JavaDoc for JPA 2.0? 在哪里可以下载 JPA 2.0 的 JavaDoc?

This trick worked for me in Eclipse Luna (4.4.2): For a jar file I am using (htsjdk), I packed the source in a separate jar file (named htsjdk-2.0.1-src.jar; I could do this since htsjdk is open source) and stored it in the lib-src folder of my project.这个技巧在 Eclipse Luna (4.4.2) 中对我有用:对于我使用的 jar 文件 (htsjdk),我将源代码打包在一个单独的 jar 文件中(名为 htsjdk-2.0.1-src.jar;我可以这样做因为 htsjdk 是开源的)并将其存储在我的项目的 lib-src 文件夹中。 In my own Java source I selected an element I was using from the jar and hit F3 (Open declaration).在我自己的 Java 源代码中,我从 jar 中选择了一个我正在使用的元素,然后按 F3(打开声明)。 Eclipse opened the class file and showed the button "Attach source". Eclipse 打开类文件并显示“附加源”按钮。 I clicked the button and pointed to the src jar file I had just put into the lib-src folder.我单击按钮并指向我刚刚放入 lib-src 文件夹中的 src jar 文件。 Now I get the Javadoc when hovering over anything I'm using from the jar.现在,将鼠标悬停在 jar 中使用的任何内容上时,我会得到 Javadoc。

如果您使用的是 maven,请执行以下操作:

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

You could specify the online Javadoc location for a particular JAR in Eclipse.您可以为 Eclipse 中的特定 JAR 指定在线 Javadoc 位置。 This saved my day when I wasn't able to find any downloadable Javadocs for Kafka.当我无法为 Kafka 找到任何可下载的 Javadoc 时,这挽救了我的一天。

  1. In the Package Explorer , right click on the intended JAR (under the project's Referenced Libraries or Maven Dependences or anything as such) and click on Properties .Package Explorer ,右键单击预期的 JAR(在项目的 Referenced Libraries 或 Maven Dependences 或任何类似内容下),然后单击Properties
  2. Click on Javadoc Location .单击Javadoc Location
  3. In the Javadoc location path field under Javadoc URL, enter the URL of the online Javadocs, which most likely ends with /<version>/javadoc/ .在 Javadoc URL 下的Javadoc location path字段中,输入在线 Javadoc 的 URL,该 URL 很可能以/<version>/javadoc/结尾。 For example, Kafka 2.3.0's Javadocs are located at http://www.apache.org/dist/kafka/2.3.0/javadoc/ (you might want to change https to http in your URL, as it raised an invalid location warning after clicking on Validate... for me).例如,Kafka 2.3.0 的 Javadoc 位于http://www.apache.org/dist/kafka/2.3.0/javadoc/ (您可能希望将 URL 中的https更改为http ,因为它提出了一个无效的位置单击“ Validate...对我而言”后发出警告)。

To attach the Java source code with Eclipse,要使用 Eclipse 附加 Java 源代码,

When you install the JDK, you must have selected the option to install the Java source files too.安装 JDK 时,您也必须选择安装 Java 源文件的选项。 This will copy the src.zip file in the installation directory.这将复制安装目录中的 src.zip 文件。 In Eclipse, go to Window -> Preferences -> Java -> Installed JREs -> Add and choose the JDK you have in your system.在 Eclipse 中,转到 Window -> Preferences -> Java -> Installed JREs -> Add 并选择您系统中的 JDK。 Eclipse will now list the JARs found in the dialog box. Eclipse 现在将列出在对话框中找到的 JAR。 There, select the rt.jar and choose Source Attachment.在那里,选择 rt.jar 并选择 Source Attachment。 By default, this will be pointing to the correct src.zip.默认情况下,这将指向正确的 src.zip。 If not, choose the src.zip file which you have in your java installation directory.如果没有,请选择您在 java 安装目录中的 src.zip 文件。 java source attach in eclipse Similarly, if you have the javadoc downloaded in your machine, you can configure that too in this dialog box. java source attach in eclipse 同样,如果你在你的机器上下载了javadoc,你也可以在这个对话框中配置它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Eclipse中为jar附加javadoc? - How to attach javadoc for jar in eclipse? 一般情况下,如何在Eclipse中将jar文件附加到源文件? - How to attach jar file to source file in Eclipse in a general case? 附上jar的Eclipse中的源码 - Attach the Source in Eclipse of a jar 如何获得控制台输出(例如,在eclipse上)并将相同的输出写入/复制到文件? - how to get a console output (e.g. on eclipse) AND write/copy the same output to file? Intellij IDEA:如何查看 class(例如 Color.html)的 javadoc 的 *整个页面*? - Intellij IDEA: How to view *entire page* of javadoc for a class (e.g. Color.html)? Java:如何将JDK类(例如javax。*)添加到自定义JavaDoc索​​引中? - Java: How to add JDK classes (e.g. javax.*) into custom JavaDoc indexes? 如何在Eclipse项目中为lib附加源而没有“ sources JAR”? - How to attach source in Eclipse project for lib with no “sources JAR”? 在Eclipse中,如何使用“ Workspace…”语法(例如$ {workspace_loc:/ myworkspace})指定文件(用于控制台日志)? - In Eclipse, how do you specify a file using the “Workspace…” syntax (e.g. ${workspace_loc:/myworkspace} ) (for a console log)? 启动并获取.jar的输出(例如Minecraft Bukkit .jar) - Start and get output of a .jar (E.g. Minecraft Bukkit .jar) 如何在 eclipse 中自动附加 javadoc 或指定 javadoc 位置 - How to attach javadoc or specify javadoc location in eclipse automatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM