Java 9 改进 Javadoc

javadoc 工具可以生成 Java 文档, Java 9 的 javadoc 的输出现在符合兼容 HTML5 标准。

Java 9 之前的旧版本文档

考虑以下文件代码 C:/JAVA/Tester.java:

实例

  1. /**
  2. * @author MahKumar
  3. * @version 0.1
  4. */
  5. public class Tester {
  6. /**
  7. * Default method to be run to print
  8. * <p>Hello world</p>
  9. * @param args command line arguments
  10. */
  11. public static void main(String []args) {
  12. System.out.println("Hello World");
  13. }
  14. }

使用 jdk 7 的 javadoc 生成文档:

  1. C:\JAVA>javadoc -d C:/JAVA Tester.java
  2. Loading source file tester.java...
  3. Constructing Javadoc information...
  4. Standard Doclet version 1.7.0_21
  5. Building tree for all the packages and classes...
  6. Generating C:\JAVA\Tester.html...
  7. Generating C:\JAVA\package-frame.html...
  8. Generating C:\JAVA\package-summary.html...
  9. Generating C:\JAVA\package-tree.html...
  10. Generating C:\JAVA\constant-values.html...
  11. Building index for all the packages and classes...
  12. Generating C:\JAVA\overview-tree.html...
  13. Generating C:\JAVA\index-all.html...
  14. Generating C:\JAVA\deprecated-list.html...
  15. Building index for all classes...
  16. Generating C:\JAVA\allclasses-frame.html...
  17. Generating C:\JAVA\allclasses-noframe.html...
  18. Generating C:\JAVA\index.html...
  19. Generating C:\JAVA\help-doc.html...

执行以上命令会再 C:/JAVA 命令下生成文档页面,如下图所示:

Java 9 改进 Javadoc - 图1

Java 9 生成的文档兼容 HTML5 标准

使用 jdk 9 javadoc 命令中的 -html5 参数可以让生成的文档支持 HTML5 标准:

  1. C:\JAVA> javadoc -d C:/JAVA -html5 Tester.java
  2. Loading source file Tester.java...
  3. Constructing Javadoc information...
  4. Standard Doclet version 9.0.1
  5. Building tree for all the packages and classes...
  6. Generating C:\JAVA\Tester.html...
  7. Generating C:\JAVA\package-frame.html...
  8. Generating C:\JAVA\package-summary.html...
  9. Generating C:\JAVA\package-tree.html...
  10. Generating C:\JAVA\constant-values.html...
  11. Building index for all the packages and classes...
  12. Generating C:\JAVA\overview-tree.html...
  13. Generating C:\JAVA\index-all.html...
  14. Generating C:\JAVA\deprecated-list.html...
  15. Building index for all classes...
  16. Generating C:\JAVA\allclasses-frame.html...
  17. Generating C:\JAVA\allclasses-frame.html...
  18. Generating C:\JAVA\allclasses-noframe.html...
  19. Generating C:\JAVA\allclasses-noframe.html...
  20. Generating C:\JAVA\index.html...
  21. Generating C:\JAVA\help-doc.html...

执行以上命令会再 C:/JAVA 命令下生成文档页面,如下图所示:

Java 9 改进 Javadoc - 图2