了解以下在java 10 版本中对Javadoc 的变化。
- 带例子的摘要标签指南
- 支持多个样式表的Javadoc工具变化
Java 10 Javadoc摘要标签
java 10 引入了许多语言变化。
它还引入了java文档的变化--{@summary} tag 。
summary 标签提供了一个单行句子来告诉人们该方法或API到底要做什么。
这可以应用于methods 或classes 。目前,没有摘要标签。默认情况是将包括period 或dot 和space 在内的内容放在最后。
语法
{@summary single line sentence}
java10 summary tag 示例
下面是一个摘要标签的例子,内容如下
如何生成方法和API类的摘要描述?
在下面的例子中:
- 创建了四个方法 - Create, Update, Read, 和 method.
- 创建和更新是用默认的摘要内容记录的,没有摘要标签。
- 读取和删除方法是用{@summary}标签来记录的
下面是一个摘要标签的例子
public class EmployeeAPI {
/**
* This method's create a Employee record in Database. Method do following
* things:
*
* create Employee
* Insert into Database
* return void
*
*/
public void create() {
}
/**
* This method's update a Employee record in Database. Method do following
* things:
*
* update Employee
* Update Employee in Database
* return void
*
*/
public void update() {
}
/**
* {@summary This method's read a Employee record in Database. Method do
* following things:
*
* Read Employee
* Read Employee from Database
* return void
*
* }
*/
public void read() {
}
/**
* {@summary This method's delete a Employee record in Database. Method do
* following things:
*
* delete Employee
* Delete Employee in Database
* return void
*
* }
*/
public void delete() {
}
}
使用Javadoc 工具,生成了上述代码的java文档
B:\Workspace\cloudhadoop\src>java --version
java 10.0.2 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
B:\Workspace\cloudhadoop\src>javac --version
javac 10.0.2
B:\Workspace\cloudhadoop\src>javadoc EmployeeAPI.java
Loading source file EmployeeAPI.java...
Constructing Javadoc information...
Javadoc: warning - You have not specified the version of HTML to use.
The default is currently HTML 4.01, but this will change to HTML5
in a future release. To suppress this warning, please specify the
a version of HTML used in your documentation comments and to be
generated by this doclet, using the -html4 or -html5 options.
Standard Doclet version 10.0.2
Building tree for all the packages and classes...
Generating .\EmployeeAPI.html...
Generating .\package-frame.html...
Generating .\package-summary.html...
Generating .\package-tree.html...
Generating .\constant-values.html...
Building index for all the packages and classes...
Generating .\overview-tree.html...
Generating .\index-all.html...
Generating .\deprecated-list.html...
Building index for all classes...
Generating .\allclasses-frame.html...
Generating .\allclasses-frame.html...
Generating .\allclasses-noframe.html...
Generating .\allclasses-noframe.html...
Generating .\index.html...
Generating .\help-doc.html...
使用以下两个选项生成java代码的文档 使用maven 命令或javadoc 命令
这里是maven命令
mvn javadoc:javadoc
javadoc 是maven的目标,用于为maven java项目生成java文档,输出为HTML文件。使用Javadoc工具
Javadoc是一个生成java文档的命令行工具,随着java 10的发展,Javadoc支持使用`-add stylesheets的多个样式表,如下所示。
Javadoc --add-stylesheet
它用给定的样式表生成一个HTML输出文件。