简体   繁体   English

Eclipse如何链接包含javadocs / source的jar和它的二进制文件?

[英]Eclipse how to link a jar containing javadocs/source with its binary?

I would like to have the javadoc comments contained in a jar file show in eclipse when I hover over a class. 当我将鼠标悬停在一个类上时,我想在eclipse中显示包含在jar文件中的javadoc注释。

For example, after downloading JODA-2.0, three jars are obtained: 例如,下载JODA-2.0后,获得三个罐子:

In eclipse, [right click project -> Properties -> Java Build Path -> Libraries -> ADD JARs...] includes the binary in the project (can reference those classes) for joda-time-2.0.jar. 在eclipse中,[右键单击项目 - >属性 - > Java构建路径 - >库 - > ADD JAR ...]包含项目中的二进制文件(可以引用这些类),用于joda-time-2.0.jar。

But how can I link in the sources/javadoc comments contained in the other two jar files so that when I hover over those classes I see the javadocs? 但是如何链接其他两个jar文件中包含的sources / javadoc注释,以便当我将鼠标悬停在这些类上时,我会看到javadocs?

Adding the other two jars (joda-time-2.0-javadoc.jar and joda-time-2.0-sources.jar) to the build path does not link the javadocs or the source. 将其他两个jar(joda-time-2.0-javadoc.jar和joda-time-2.0-sources.jar)添加到构建路径不会链接javadoc或源。

  1. Right click over the project -> Build path -> Configure build path 右键单击项目 - >构建路径 - >配置构建路径
  2. In the new window, go to the "Libraries" tab. 在新窗口中,转到“库”选项卡。
  3. Select the library and expand it. 选择库并展开它。
  4. There are 4 child options. 有4个孩子选择。 Select "Javadoc location" and click the "Edit" button on the right. 选择“Javadoc location”并单击右侧的“Edit”按钮。
  5. Now you can add a jar file containing the docs. 现在您可以添加包含文档的jar文件。 This would be just a zip file with the extension changed to jar. 这只是一个zip文件,扩展名改为jar。 Make sure inside the jar the index.html is in the root. 确保jar内的index.html在根目录中。 You can press the "Validate" button to check everything is ok. 您可以按“验证”按钮检查一切正常。

You can try to CTRL + click on a class that has no source attached (do that in editor). 您可以尝试按CTRL +单击没有附加源的类(在编辑器中执行此操作)。 When it shows you some info about the class you'll see the button that guides to attach source dialog. 当它向您显示有关该类的一些信息时,您将看到指导附加源对话框的按钮。 Click it and in dialog that pops up pick the source/javadoc location for your class. 单击它,然后在弹出的对话框中选择您的类的源/ javadoc位置。

You can also do that from project build path settings you are mentioning: pick libraries tab, expand the library (jar) you want and you'll be offered to pick: source attachment, javadoc attachment, native library location, etc. You just pick whatever you want and edit its current settings. 您也可以从您提到的项目构建路径设置中执行此操作:选择库选项卡,展开您想要的库(jar),您将可以选择:源附件,javadoc附件,本机库位置等。您只需选择无论你想要什么,并编辑其当前设置。

Or you can do as @JB Nizet said... 或者你可以像@JB Nizet所说的那样......

Right-click on the jar (the one with the class files), choose "Properties", the "Javadoc location", and choose the jar file with the javadoc. 右键单击jar(带有类文件的jar),选择“Properties”,“Javadoc location”,然后选择带有javadoc的jar文件。 Do similarly for the source jar, using "Java source attachment". 使用“Java源附件”对源jar执行类似操作。

You can also edit the classpathentry in the file ".classpath" in your eclipse project. 您还可以在eclipse项目的“.classpath”文件中编辑classpathentry。 This can be helpful if you want to modify many entries at once or if you want to generate the path. 如果要一次修改多个条目或者要生成路径,这可能会有所帮助。 eg: 例如:

<classpathentry kind="var" path="HOME/3rdparty/junit.jar" sourcepath="/SOURCE/junit_src.zip"/>

The easiest way is : 最简单的方法是:

  1. Press control+(The word for which you want to see the Java doc) 按控制键+(您要查看Java文档的单词)
  2. A page will appear that has a button for attach source.Click This 将出现一个页面,其中包含用于附加源的按钮。单击此按钮
  3. Select External location. 选择外部位置。
  4. Browse The location to Java folder than your jdk .Than select src .zip. 浏览Java文件夹的位置而不是jdk 。然后选择src .zip。
  5. press OK. 按确定。

The Problem is Solved. 问题已经解决了。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM