如何使 javadoc 继承适用于外部 API? (使用 Maven2)
当类重写具体方法或实现和抽象方法时,除非显式重写,否则会自动继承 Javadoc。
或者,至少该工具尝试做到这一点。它似乎不适用于链接的外部 API。例如,当我在代码中实现 java.util.Map 或 JRE 中的其他内容时,javadocs 不会从 JRE javadocs/apidocs 继承/复制。
在我的具体情况下,我尝试在 Maven2 Javadoc 插件中配置它,但当我直接运行 javadoc CLI 工具时它是相同的。
我的 Maven2 Javadoc 插件配置当前如下所示:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<stylesheet>maven</stylesheet>
<links>
<link>http://download.oracle.com/javase/6/docs/api</link>
</links>
</configuration>
</plugin>
</plugins>
</reporting>
有关如何使其工作的任何指示?
When a class overrides a concrete method or implements and abstract method, the Javadoc is automatically inherited unless explicitly overwritten.
Or, at least the tool tries to do this. It seems it does not work for linked external APIs. For instance, when I in my code implement java.util.Map
, or something else from the JRE, the javadocs are not inherited/copied from the JRE javadocs/apidocs.
In my specific case, I am trying to configure this in the Maven2 Javadoc plugin, but it is the same when I run the javadoc CLI tool directly.
My Maven2 Javadoc plugin configuration currently looks like this:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<stylesheet>maven</stylesheet>
<links>
<link>http://download.oracle.com/javase/6/docs/api</link>
</links>
</configuration>
</plugin>
</plugins>
</reporting>
Any pointers on how to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如@Stephen提到的,继承方法的源文件必须可用,并且必须位于
-sourcepath
指定的路径上。 Javadoc 工具文档对此进行了解释:所以你必须使用
javadoc 插件的可选配置参数(默认包含项目的源)。顺便说一下,
是别的东西,
用于添加外部项目的交叉引用链接。实际上,它们不应该用于 JDK。来自配置链接:假设您在编译器插件中配置了 1.6
source
级别,则指向 Java API 的交叉引用链接就可以正常工作(链接指向 http://download.oracle.com/javase/6/docs/api/),对于 Java API 无需添加任何内容。诡异的。您是否确实按照文档指定了编译器
源
级别?以防万一,这对我有用:As @Stephen mentioned, the source file for the inherited method must be available and must be on the path specified by
-sourcepath
. This is explained in the Javadoc tool documentation:So you'd have to use the
<sourcepath>
optional configuration parameter of the javadoc plugin (which contains by default the sources of the project).By the way,
<links/>
are something else,<links/>
are used to add cross reference links to external projects. And actually, they shouldn't be used for the JDK. From Configuring links:Assuming you configured a 1.6
source
level in the compiler plugin, cross references links to the Java API just works (links point to http://download.oracle.com/javase/6/docs/api/), there is nothing to add for the Java API.Weird. Did you actually specify the complier
source
level as documented? Just in case, here is what works for me:我无法给你一个明确的答案,但我认为这个难题中缺少的一部分是
javadoc
实用程序需要能够找到相关外部的源代码用于 javadoc 继承的 API 可以正常工作。I cannot give you a definitive answer, but I think that the missing piece in the puzzle is that the
javadoc
utility needs to be able to find the source code of the relevant external APIs for javadoc inheritance to work.我在 StackOverflow 上有一个类似的问题,它帮助我比这个问题的公认答案更好地解决了这个问题: Java API核心类的maven-javadoc-plugin和inheritDoc
摘要:
为了从 Java 核心类继承 Javadoc,您需要解压缩它们的源代码并将它们包含在 Javadoc 构建中。 Java 核心类的源代码在 JDK 发行版中的 src.zip 文件中提供。
I had a similar question on StackOverflow which helped me solve this problem better than the accepted answer of this questsion: maven-javadoc-plugin and inheritDoc for Java API core classes
Summary:
In order to inherit the Javadoc from Java core classes, you need to unzip their sources and include them in the Javadoc build. The sources of the Java core classes are are provided in a
src.zip
file within the JDK distro.