在这篇博文中,我们将学习以下对Javadoc java 10中的变化。
- 带例子的摘要标签指南
- 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 and methods.
- 创建和更新是用默认的摘要内容记录的,没有摘要标签。
- 读取和删除方法用{@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
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的目标,用于为maven java项目生成java文档,输出为HTML文件 使用Javadoc工具 Javadoc是一个命令行工具,用于生成java文档 使用java 10,Javadoc支持多个样式表,使用-add-stylesheets ,如下所示
这将生成具有给定应用样式表的HTML输出文件。