javadoc

Generates HTML pages of API documentation from Java source files.

Synopsis

Names of packages that you want to document, separated by spaces, for example java.lang java.lang.reflect java.awt . If you want to also document the subpackages, use the -subpackages option to specify the packages.

By default, javadoc looks for the specified packages in the current directory and subdirectories. Use the -sourcepath option to specify the list of directories where to look for packages.

source-files

Names of Java source files that you want to document, separated by spaces, for example Class.java Object.java Button.java . By default, javadoc looks for the specified classes in the current directory. However, you can specify the full path to the class file and use wildcard characters, for example /home/src/java/awt/Graphics*.java . You can also specify the path relative to the current directory.

Command-line options, separated by spaces. See Options.

Names of files that contain a list of javadoc command options, package names and source file names in any order.

Description

The javadoc command parses the declarations and documentation comments in a set of Java source files and produces a corresponding set of HTML pages that describe (by default) the public and protected classes, nested classes (but not anonymous inner classes), interfaces, constructors, methods, and fields. You can use the javadoc command to generate the API documentation or the implementation documentation for a set of source files.

You can run the javadoc command on entire packages, individual source files, or both. When documenting entire packages, you can either use the -subpackages option to recursively traverse a directory and its subdirectories, or to pass in an explicit list of package names. When you document individual source files, pass in a list of Java source file names. See Simple Examples.

Conformance

The standard doclet does not validate the content of documentation comments for conformance nor does it attempt to correct any errors in documentation comments. Be aware of the problems that may arise when generating non-conforming output or output containing executable content, such as JavaScript, when running the javadoc command. The standard doclet does provide the -Xdoclint option to help you detect common problems in documentation comments; however, it is also recommended to check the generated output with any appropriate conformance and checking tools.

For more information about conformance requirements for HTML5 documents, see Conformance requirements in the HTML5 specification. For more information about security issues related to web pages, see Open Web Application Security Project (OWASP).

Process Source Files

The javadoc command processes files that end in source and other files described in Source Files. If you run the javadoc command by passing in individual source file names, then you can determine exactly which source files are processed. However, that is not how most developers want to work, because it is simpler to pass in package names. The javadoc command can be run three ways without explicitly specifying the source file names. You can pass in package names, use the -subpackages option, or use wild cards with source file names. In these cases, the javadoc command processes a source file only when the file fulfills all of the following requirements:

Processing Links

During a run, the javadoc command adds cross-reference links to package, class, and member names that are being documented as part of that run. Links appear in the following places. See Javadoc Tags for a description of the @ tags.

You can add links to existing text for classes not included on the command line (but generated separately) by way of the -link and -linkoffline options.

Processing Details

The javadoc command produces one complete document every time it runs. It does not do incremental builds that modify or directly incorporate the results from earlier runs. However, the javadoc command can link to results from other runs.

The javadoc command implementation requires and relies on the Java compiler. The javadoc command calls part of the javac command to compile the declarations and ignore the member implementations. The javadoc command builds a rich internal representation of the classes that includes the class hierarchy and use relationships to generate the HTML. The javadoc command also picks up user-supplied documentation from documentation comments in the source code. See Documentation Comments.

The javadoc command runs on source files that are pure stub files with no method bodies. This means you can write documentation comments and run the javadoc command in the early stages of design before API implementation.

Relying on the compiler ensures that the HTML output corresponds exactly with the actual implementation, which may rely on implicit, rather than explicit, source code. For example, the javadoc command documents default constructors that are present in the compiled class files but not in the source code.

In many cases, the javadoc command lets you generate documentation for source files with incomplete or erroneous code. You can generate documentation before all debugging and troubleshooting is done. The javadoc command does primitive checking of documentation comments.

When the javadoc command builds its internal structure for the documentation, it loads all referenced classes. Because of this, the javadoc command must be able to find all referenced classes, whether bootstrap classes, extensions, or user classes. See How Classes Are Found at
https://docs.oracle.com/javase/8/docs/technotes/tools/findingclasses.html

Typically, classes you create must either be loaded as an extension or in the javadoc command class path.

Javadoc Doclets

You can customize the content and format of the javadoc command output with doclets. The javadoc command has a default built-in doclet, called the standard doclet, that generates HTML-formatted API documentation. You can modify or make a subclass of the standard doclet, or write your own doclet to generate HTML, XML, MIF, RTF or whatever output format you want.

When a custom doclet is not specified with the -doclet option, the javadoc command uses the default standard doclet. The javadoc command has several options that are available regardless of which doclet is being used. The standard doclet adds a supplementary set of command-line options. See Options.

Source Files

The javadoc command generates output that originates from the following types of source files: Java language source files for classes ( .java ), package comment files, overview comment files, and miscellaneous unprocessed files. This section also describes test files and template files that can also be in the source tree, but that you want to be sure not to document.

Class Source Files

Each class or interface and its members can have their own documentation comments contained in a source file. See Documentation Comments.

Package Comment Files

Each package can have its own documentation comment, contained in its own source file, that the javadoc command merges into the generated package summary page. You typically include in this comment any documentation that applies to the entire package.

To create a package comment file, you can place your comments in one of the following files:

A package can have a single package.html file or a single package-info.java file, but not both. Place either file in the package directory in the source tree with your source files.

The package-info.java File

The package-info.java file can contain a package comment of the following structure. The comment is placed before the package declaration.

Note: The comment separators /** and */ must be present, but the leading asterisks on the intermediate lines can be left off.

/** * Provides the classes necessary to create an * applet and the classes an applet uses * to communicate with its applet context. * 

* The applet framework involves two entities: * the applet and the applet context. * An applet is an embeddable window (see the * class) with a few extra * methods that the applet context can use to * initialize, start, and stop the applet. * * @since 1.0 * @see java.awt */ package java.lang.applet;

The package.html File

The package.html file can contain a package comment of the following structure. The comment is placed in the element.

  Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context. 

The applet framework involves two entities: the applet and the applet context. An applet is an embeddable window (see the class) with a few extra methods that the applet context can use to initialize, start, and stop the applet. @since 1.0 @see java.awt

The package.html file is a typical HTML file and does not include a package declaration. The content of the package comment file is written in HTML with one exception. The documentation comment should not include the comment separators /** and */ or leading asterisks. When writing the comment, make the first sentence a summary about the package, and do not put a title or any other text between the tag and the first sentence. You can include package tags. All block tags must appear after the main description. If you add an @see tag in a package comment file, then it must have a fully qualified name.

Processing the Comment File

When the javadoc command runs, it searches for the package comment file. If the package comment file is found, then the javadoc command does the following:

Overview Comment Files

Each application or set of packages that you are documenting can have its own overview documentation comment that is kept in its own source file, that the javadoc command merges into the generated overview page. You typically include in this comment any documentation that applies to the entire application or set of packages.

You can name the file anything you want such as overview.html and place it anywhere. A typical location is at the top of the source tree.

For example, if the source files for the java.applet package are contained in the C:\user\src\java\applet directory, then you could create an overview comment file at C:\user\src\overview.html.

You can have multiple overview comment files for the same set of source files in case you want to run the javadoc command multiple times on different sets of packages. For example, you could run the javadoc command once with -private for internal documentation and again without that option for public documentation. In this case, you could describe the documentation as public or internal in the first sentence of each overview comment file.

The content of the overview comment file is one big documentation comment that is written in HTML. Make the first sentence a summary about the application or set of packages. Do not put a title or any other text between the tag and the first sentence. All tags except inline tags, such as an < @link>tag, must appear after the main description. If you add an @see tag, then it must have a fully qualified name.

When you run the javadoc command, specify the overview comment file name with the -overview option. The file is then processed similarly to that of a package comment file. The javadoc command does the following:

Unprocessed Files

Your source files can include any files that you want the javadoc command to copy to the destination directory. These files usually include graphic files, example Java source and class files, and self-standing HTML files with a lot of content that would overwhelm the documentation comment of a typical Java source file.

To include unprocessed files, put them in a directory called doc-files. The doc-files directory can be a subdirectory of any package directory that contains source files. You can have one doc-files subdirectory for each package.

For example, if you want to include the image of a button in the java.awt.Button class documentation, then place the image file in the \src\java\awt\doc-files directory. Do not place the doc-files directory at \src\java\doc-files, because java is not a package. It does not contain any source files.

All links to the unprocessed files must be included in the code because the javadoc command does not look at the files. The javadoc command copies the directory and all of its contents to the destination. The following example shows how the link in the Button.java documentation comment might look:

/** * This button looks like this: *  */

Test and Template Files

You can store test and template files in the source tree in the same directory with or in a subdirectory of the directory where the source files reside. To prevent test and template files from being processed, run the javadoc command and explicitly pass in individual source file names.

Test files are valid, compilable source files. Template files are not valid, compatible source files, but they often have the .java suffix.

If you want your test files to belong to either an unnamed package or to a package other than the package that the source files are in, then put the test files in a subdirectory underneath the source files and give the directory an invalid name. If you put the test files in the same directory with the source and call the javadoc command with a command-line argument that indicates its package name, then the test files cause warnings or errors. If the files are in a subdirectory with an invalid name, then the test file directory is skipped and no errors or warnings are issued. For example, to add test files for source files in com.package1, put them in a subdirectory in an invalid package name. The following directory name is invalid because it contains a hyphen:

com\package1\test-files\

If your test files contain documentation comments, then you can set up a separate run of the javadoc command to produce test file documentation by passing in their test source file names with wild cards, such as com/package1/test-files/*.java .

Template Files

If you want a template file to be in the source directory, but not generate errors when you execute the javadoc command, then give it an invalid file name such as Buffer-Template.java to prevent it from being processed. The javadoc command only processes source files with names, when stripped of the .java suffix, that are valid class names.

Generated Files

By default, the javadoc command uses a standard doclet that generates HTML-formatted documentation. The standard doclet generates basic content, cross-reference, and support pages described here. Each HTML page corresponds to a separate file. The javadoc command generates two types of files. The first type is named after classes and interfaces. The second type contain hyphens (such as package-summary.html) to prevent conflicts with the first type of file.

Basic Content Pages

Cross-Reference Pages

Support Pages

HTML Frames

The javadoc command generates the minimum number of frames (two or three) necessary based on the values passed to the command. It omits the list of packages when you pass a single package name or source files that belong to a single package as an argument to the javadoc command. Instead, the javadoc command creates one frame in the left-hand column that displays the list of classes. When you pass two or more package names, the javadoc command creates a third frame that lists all packages and an overview page (overview-summary.html). To bypass frames, click the No Frames link or enter the page set from the overview-summary.html page.

Generated File Structure

The generated class and interface files are organized in the same directory hierarchy that Java source files and class files are organized. This structure is one directory per subpackage.

For example, the document generated for the java.applet.Applet class would be located at java\applet\Applet.html.

The file structure for the java.applet package follows, assuming that the destination directory is named apidocs . All files that contain the word frame appear in the upper-left or lower-left frames, as noted. All other HTML files appear in the right-hand frame.

Directories are bold. The asterisks (*) indicate the files and directories that are omitted when the arguments to the javadoc command are source file names rather than package names. When arguments are source file names, an empty package list is created. The doc-files directory is not created in the destination unless it exists in the source tree. See Generated Files.