Introduction to javadoc command
The javadoc tool is used to create nicely formatted documents from java source code. The tool can be found in the bin directory of java . The tool uses a ‘doclet’ to convert java source code into a document. The standard doclet produces an HTML document but you can have doclets that create pdf, postscript etc.
What can javadoc document?
javadoc looks for source files in the directory that you specify and documents all source files for the packages (and optionally subpackages) that you specify. It documents javadoc comments from public and protected classes, nested classes, interfaces, constructors (implicit too), methods and fields. It can add reference links to other pages. It creates a new document every time and does not create an incremental build.
What’s new in Java 9 javadoc?
javadocs created in java 9 are HTML5 compliant. Note that to be fully compliant any html written inside the javadoc comments have to be compliant too. Java 9 also adds a search box in the javadocs pages.
The image below shows a demo project with a single class.
To generate javadoc for this project, use this command
/usr/lib/jvm/jdk-10.0.1/bin/javadoc --source-path src/ -d ~/java/java9/doc/ com.st.java9
the –source-path specifies the path where the source files can be found. com.st.java9 is the name of the package that we want to document. All classes under this package will be documented. To include subpackages use –subpackages.
-d is used to specify the output folder where the documentation is created. look for ‘index.html’ file in this folder. This is the entry point to the documentation. The search box is located on top right.
This is how the search box looks like.
Javadoc has many other options that you can use such as adding a header/footer, or including types and members with a specific visibility (private, public, protectected) etc. The options can be divided into two types, the javadoc options and the doclet options. For more details on the options use