1

I'm using the Javadoc tool to document some code, and the results uses fully qualified names for system classes, such as java.lang.String. Is there a way to stop that specifically for classes in the java.* and javax.* heirarchy?

For example, a method definition like this:

    * @param field String to write.
    * @throws IOException If the underlying stream throws an exception.
    */
   public void writeField( String field ) throws IOException {
      // etc.

Produces Javadoc output like this:

writeField

public void writeField​(java.lang.String field) throws java.io.IOException

    ...etc.

Parameters:
    field - String to write.
Throws:
    java.io.IOException - If the underlying stream throws an exception.

I'd like the reference to java.lang.String to be just String, and the reference to java.io.IOException likewise to be just IOException.

Any ideas?


Edit and update re. the accepted answer below:

In NetBeans 10, what I did to fix this was go to the Project view, then switch to Files view. Then in the project files, locate nbproject/project.properties and open that file (right click, choose open).

In the properties view, scroll down on the left until you see javadoc.additionalparam. Then add the following to the right side of that property (in my case its value was empty) -link https://docs.oracle.com/en/java/javase/11/docs/api/

Then save (control-S) the file and build. The Javadocs now look how I wanted. Thank you Slaw!

4

1 回答 1

2

如果 Javadoc 无法链接到类/方法/等,则它会输出完全限定名称。要让它只输出简单的名称,您必须链接到外部 Javadoc。这是通过-link <url>该工具的命令行选项完成的javadoc。要链接到 SE 类(即java.*javax.*),一种选择是使用:

javadoc -link https://docs.oracle.com/en/java/javase/11/docs/api/ [...]

[...]命令行的其余部分在哪里。您可以更改 URL 以指向不同版本的 Java(例如 Java 8 而不是 Java 11)。

还有一个-linkoffline <url1> <url2>选项。

注意:我相信这两个选项都是由“标准 doclet”提供的。如果不使用标准 doclet,这些选项可能不可用或工作方式不同。

于 2019-01-28T22:53:47.523 回答