JAVADOC(1)

πŸ“¦ version 21.0.13.0.3.u1, in arch rolling

πŸ’… javadoc β€” JDK Commands πŸŽ€

okay so this is the JAVADOC(1) manual page, and it’s literally the glow-up guide for javadoc, the JDK tool that makes API docs out of Java source files. bestie, it’s giving β€œturn your comments into HTML” energy, and we’re gonna go through every single detail. no skipping. periodt. ✨

🌸 NAME 🌸

javadoc β€” generate HTML pages of API documentation from Java source files. 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

javadoc [options] [packagenames] [sourcefiles] [@files]
  • options β€” command-line options, separated by spaces. See Standard javadoc Options, Extra javadoc Options, Standard Options for the Standard Doclet, and Extra Options for the Standard Doclet. πŸ’…
  • packagenames β€” names of packages you want to document, separated by spaces, for example java.lang java.lang.reflect java.awt. If you also wanna 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. πŸŽ€

  • sourcefiles β€” names of Java source files 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. πŸ¦‹
  • @files β€” names of files that contain a list of javadoc tool options, package names, and source file names in any order. πŸ“

🌈 DESCRIPTION 🌈

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

You can run the javadoc tool on entire packages, individual source files, or both. When documenting entire packages, you can use the -subpackages option either 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. πŸ’–

πŸ’– 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. Anyone running javadoc is advised to be aware of the problems that may arise when generating non-conformant output or output containing executable content, such as JavaScript. The Standard Doclet does provide the DocLint feature to help developers detect common problems in documentation comments; but it is also recommended to check the generated output with any appropriate conformance and other checking tools. 😭

For more details on the conformance requirements for HTML5 documents, see Conformance requirements in the HTML5 Specification: https://www.w3.org/TR/html5/infrastructure.html#conformance-requirements. For more details on security issues related to web pages, see the Open Web Application Security Project (OWASP) page: https://www.owasp.org. 🫢

πŸ”₯ OPTIONS πŸ”₯

javadoc supports command-line options for both the main javadoc tool and the currently selected doclet. The Standard Doclet is used if no other doclet is specified. ✨

GNU-style options (that is, those beginning with --) can use an equal sign (=) instead of whitespace characters to separate the name of an option from its value. πŸŽ€

⭐ Standard javadoc Options ⭐

The following core javadoc options are equivalent to corresponding javac options. See Standard Options in javac for the detailed descriptions of using these options: πŸ’…

  • --add-modules
  • -bootclasspath
  • --class-path, -classpath, or -cp
  • --enable-preview
  • -encoding
  • -extdirs
  • --limit-modules
  • --module
  • --module-path or -p
  • --module-source-path
  • --release
  • --source or -source
  • --source-path or -sourcepath
  • --system
  • --upgrade-module-path

The following options are the core javadoc options that are not equivalent to a corresponding javac option: πŸ¦‹

  • -breakiterator β€” computes the first sentence with BreakIterator. The first sentence is copied to the package, class, or member summary and to the alphabetic index. The BreakIterator class is used to determine the end of a sentence for all languages except for English.
    • English default sentence-break algorithm --- Stops at a period followed by a space or an HTML block tag, such as <P>.
    • Breakiterator sentence-break algorithm --- Stops at a period, question mark, or exclamation point followed by a space when the next word starts with a capital letter. This is meant to handle most abbreviations (such as "The serial no. is valid", but will not handle "Mr. Smith"). The -breakiterator option doesn't stop at HTML tags or sentences that begin with numbers or symbols. The algorithm stops at the last period in ../filename, even when embedded in an HTML tag. 😭
  • -doclet class β€” generates output by using an alternate doclet. Use the fully qualified name. This doclet defines the content and formats the output. If the -doclet option isn't used, then the javadoc tool uses the standard doclet for generating the default HTML format. This class must contain the start(Root) method. The path to this starting class is defined by the -docletpath option. πŸ‘‘
  • -docletpath path β€” specifies where to find doclet class files (specified with the -doclet option) and any JAR files it depends on. If the starting class file is in a JAR file, then this option specifies the path to that JAR file. You can specify an absolute path or a path relative to the current directory. If classpathlist contains multiple paths or JAR files, then they should be separated with a colon (:) on Linux and a semi-colon (;) on Windows. This option isn't necessary when the doclet starting class is already in the search path. πŸŽ€
  • -exclude pkglist β€” unconditionally excludes the specified packages and their subpackages from the list formed by -subpackages. It excludes those packages even when they would otherwise be included by some earlier or later -subpackages option.

The following example would include java.io, java.util, and java.math (among others), but would exclude packages rooted at java.net and java.lang. Notice that these examples exclude java.lang.ref, which is a subpackage of java.lang. πŸ’…

  • Linux and macOS:
javadoc -sourcepath /home/user/src -subpackages java -exclude java.net:java.lang
  • Windows:
javadoc -sourcepath \user\src -subpackages java -exclude java.net:java.lang
  • --expand-requires value β€” instructs the javadoc tool to expand the set of modules to be documented. By default, only the modules given explicitly on the command line are documented. Supports the following values:
    • transitive: additionally includes all the required transitive dependencies of those modules.
    • all: includes all dependencies. πŸ¦‹
  • --help, -help, -h, or -? β€” prints a synopsis of the standard options. 😌
  • --help-extra or -X β€” prints a synopsis of the set of extra options. ✨
  • -Jflag β€” passes flag directly to the Java Runtime Environment (JRE) that runs the javadoc tool. For example, if you must ensure that the system sets aside 32 MB of memory in which to process the generated documentation, then you would call the -Xmx option as follows: javadoc -J-Xmx32m -J-Xms32m com.mypackage. Be aware that -Xms is optional because it only sets the size of initial memory, which is useful when you know the minimum amount of memory required.

There is no space between the J and the flag. ⚠️

Use the -version option to report the version of the JRE being used to run the javadoc tool.

javadoc -J-version
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)
  • -locale name β€” specifies the locale that the javadoc tool uses when it generates documentation. The argument is the name of the locale, as described in java.util.Locale documentation, such as en_US (English, United States) or en_US_WIN (Windows variant). 🌍

Specifying a locale causes the javadoc tool to choose the resource files of that locale for messages such as strings in the navigation bar, headings for lists and tables, help file contents, comments in the stylesheet.css file, and so on. It also specifies the sorting order for lists sorted alphabetically, and the sentence separator to determine the end of the first sentence. The -locale option doesn't determine the locale of the documentation comment text specified in the source files of the documented classes. πŸŽ€

  • -package β€” shows only package, protected, and public classes and members. πŸ“
  • -private β€” shows all classes and members. πŸ‘‘
  • -protected β€” shows only protected and public classes and members. This is the default. πŸ’–
  • -public β€” shows only the public classes and members. 🌸
  • -quiet β€” shuts off messages so that only the warnings and errors appear to make them easier to view. It also suppresses the version string. 🀫
  • --show-members value β€” specifies which members (fields or methods) are documented, where value can be any of the following:
    • public --- shows only public members
    • protected --- shows public and protected members; this is the default
    • package --- shows public, protected, and package members
    • private --- shows all members πŸ‘‘
  • --show-module-contents value β€” specifies the documentation granularity of module declarations, where value can be api or all. πŸ¦‹
  • --show-packages value β€” specifies which modules packages are documented, where value can be exported or all packages. πŸ’…
  • --show-types value β€” tells the tool which types (classes, interfaces, whatever) get actual documentation written for them. value can be literally any of these:
    • public β€” only public types get shown πŸ’…
    • protected β€” public and protected types get shown; this is the default, bestie, it's what you get if you don't say anything
    • package β€” public, protected, and package types
    • private β€” literally everything gets shown, no secrets, zero privacy, main character energy πŸ™ˆ
  • -subpackages subpkglist β€” generates docs from source files in the packages you name and recursively in all their subpackages. This one's lowkey iconic when you're adding new subpackages to your source, because they get swept up automatically, no extra work from you 🫢. Each package argument is any top-level subpackage (like java) or fully qualified package (like javax.swing) β€” and ngl it doesn't even need to contain source files. Arguments are separated by colons on all operating systems. Wildcards are not allowed, periodt. Use -sourcepath to tell it where to find the packages. Heads up though: this option does not process source files that live in the source tree but don't belong to the packages.

For example, the following commands generate documentation for packages named java and javax.swing and all of their subpackages:

  • Linux and macOS:
javadoc -d docs -sourcepath /home/user/src -subpackages java:javax.swing
  • Windows:
javadoc -d docs -sourcepath \user\src -subpackages java:javax.swing
  • -verbose β€” gives you more detailed messages while the javadoc tool runs. Without it, you get messages for loading the source files, generating the documentation (one message per source file), and sorting. With -verbose you get extra messages that specify the number of milliseconds it took to parse each Java source file. Very "tell me everything" of it ✨
  • --version β€” prints version information. That's it. That's the whole thing πŸ’–
  • -Werror β€” reports an error if any warnings occur. Like, any warning at all. Zero tolerance, we love a strict queen πŸ‘‘

πŸ§ͺ Extra javadoc Options

Note: the additional options for javadoc are subject to change without notice. Fr fr, don't get too attached 😭

The following extra javadoc options are equivalent to the corresponding javac options. See Extra Options in javac for the detailed descriptions of how to use these:

  • --add-exports
  • --add-reads
  • --patch-module
  • -Xmaxerrs
  • -Xmaxwarns

πŸ’… Standard Options for the Standard Doclet

These are the options the standard doclet itself provides, bestie. Yes, there's a whole separate crew of them:

  • --add-script file β€” adds file as an extra JavaScript file into the generated documentation. You can use this option one or more times to specify additional script files. Obsessed with a repeatable flag 🌸

Command-line example:

javadoc --add-script first_script.js --add-script second_script.js pkg_foo
  • --add-stylesheet file β€” adds file as an extra stylesheet file into the generated documentation. Just like the scripts, you can use this option one or more times to specify additional stylesheets included in the documentation πŸŽ€

Command-line example:

javadoc --add-stylesheet new_stylesheet_1.css --add-stylesheet new_stylesheet_2.css pkg_foo
  • --allow-script-in-comments β€” allows JavaScript in options and comments. That's the whole vibe check πŸ¦‹
  • -author β€” includes the @author text in the generated docs. Credit where credit is due, periodt πŸ’œ
  • -bottom html-code β€” sets the text placed at the bottom of each output file. It goes at the bottom of the page, underneath the lower navigation bar. The text can contain HTML tags and white space, but when it does, you must wrap the text in quotation marks. Use escape characters for any internal quotation marks within the text.
  • -charset name β€” sets the HTML character set for this document. name should be a preferred MIME name as specified in the IANA Registry, Character Sets [http://www.iana.org/assignments/character-sets].

For example:

javadoc -charset "iso-8859-1" mypackage

This command inserts the following line in the head of every generated page:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

The meta tag is described in the HTML standard (4197265 and 4137321), HTML Document Representation [http://www.w3.org/TR/REC-html40/charset.html#h-5.2.2].

  • -d directory β€” sets the destination directory where the javadoc tool saves the generated HTML files. If you omit -d, the files go to the current directory. The directory value can be absolute or relative to the current working directory. And don't stress β€” the destination directory is automatically created when the javadoc tool runs 🫢
    • Linux and macOS: for example, the following command generates the documentation for the package com.mypackage and saves the results in the /user/doc/ directory:
javadoc -d /user/doc/ com.mypackage
  • Windows: for example, the following command generates the documentation for the package com.mypackage and saves the results in the \user\doc\ directory:
javadoc -d \user\doc\ com.mypackage

There are three options available for use in a javadoc encoding command. The -encoding option is used for encoding the files read by the javadoc tool, while -docencoding and -charset are used for encoding the files written by the tool. Of the three available options, at most only the input and one output encoding option are used in a single encoding command. If you specify both an input and an output encoding option in a command, they must be the same value. If you specify neither output option, it defaults to the input encoding. Lowkey a whole encoding saga 😭

For example:

javadoc -docencoding "iso-8859-1" mypackage
  • -docfilessubdirs β€” recursively copies doc-file subdirectories. Enables deep copying of doc-files directories. Subdirectories and all contents get recursively copied to the destination. For example, the directory doc-files/example/images and all of its contents are copied. You can use the -excludedocfilessubdir option to exclude specific subdirectories πŸ’…
  • -doctitle html-code β€” sets the title to place near the top of the overview summary file. The text specified in the title tag gets placed as a centered, level-one heading directly beneath the top navigation bar. The title tag can contain HTML tags and white space, but when it does, you must enclose the title in quotation marks. Additional quotation marks within the title tag must be escaped. For example, javadoc -doctitle "<b>My Library</b><br>v1.0" com.mypackage.
  • -excludedocfilessubdir name1,name2... β€” excludes any subdirectories with the given names when recursively copying doc-file subdirectories. See -docfilessubdirs. And for historical reasons, : can be used anywhere in the argument as a separator instead of ,. History is weird, we respect it 🧚
  • -footer html-code β€” sets the footer text placed at the bottom of each output file. The html-code value goes to the right of the lower navigation bar. The html-code value can contain HTML tags and white space, but when it does, the html-code value must be enclosed in quotation marks. Use escape characters for any internal quotation marks within a footer.
  • -group name p1,p2... β€” groups the specified packages together on the Overview page. For historical reasons, : can be used as a separator anywhere in the argument instead of ,. Cute lil grouping moment πŸŽ€
  • -header html-code β€” sets the header text placed at the top of each output file. The header goes to the right of the upper navigation bar. The header can contain HTML tags and white space, but when it does, the header must be enclosed in quotation marks. Use escape characters for internal quotation marks within a header. For example, javadoc -header "<b>My Library</b><br>v1.0" com.mypackage.
  • -helpfile filename β€” includes the file that links to the HELP link in the top and bottom navigation bars. Without this option, the javadoc tool creates a help file help-doc.html that's hard-coded into the javadoc tool. This option lets you override the default. The filename can be any name and isn't restricted to help-doc.html. The javadoc tool adjusts the links in the navigation bar accordingly. For example:
    • Linux and macOS:
javadoc -helpfile /home/user/myhelp.html java.awt
  • Windows:
javadoc -helpfile C:\user\myhelp.html java.awt
  • -html5 β€” this option is a no-op and is just retained for backwards compatibility. It does literally nothing, it's just here for the vibes πŸ’€
  • --javafx or -javafx β€” enables JavaFX functionality. This option is enabled by default if the JavaFX library classes are detected on the module path. Two spellings, same slay ✨
  • -keywords β€” adds HTML keyword <meta> tags to the generated file for each class. These tags can help search engines that look for <meta> tags find the pages. Most search engines that search the entire internet don't look at <meta> tags, because pages can misuse them. Search engines offered by companies that confine their searches to their own website can benefit by looking at <meta> tags. The <meta> tags include the fully qualified name of the class and the unqualified names of the fields and methods. Constructors aren't included because they're identical to the class name. For example, the class String starts with these keywords:
<meta name="keywords" content="java.lang.String class">
<meta name="keywords" content="CASE_INSENSITIVE_ORDER">
<meta name="keywords" content="length()">
<meta name="keywords" content="charAt()">
  • -link url β€” makes links to javadoc docs that already exist for classes living somewhere else (external refs, iykyk). The url here is the absolute or relative URL of the directory that holds that external javadoc-generated documentation. You can drop multiple -link options in one javadoc tool run to link to multiple documents β€” stack 'em, bestie ✨

Either a package-list or an element-list file must be in this url directory, otherwise use the -linkoffline option instead. No list file, no link, no cap.

Note: the package-list and element-list files are generated by the javadoc tool itself when it generates the API documentation, and should not be modified by the user. Hands off πŸ™ˆ

When you use the javadoc tool to document packages, it reads the package-list file to figure out which packages are declared in an API. When you generate API docs for modules, it uses the element-list file to figure out which modules and packages are declared in an API. The javadoc tool then reads the names from whichever list file is appropriate and links to those packages or modules at that URL. Iconic behaviour, honestly.

When the javadoc tool runs, the url value gets copied straight into the <A HREF> links it creates. Which is exactly why url has to be the URL to the directory and not to a file. Directory. Not file. Periodt πŸ’…

You can use an absolute link for url so your docs can link to a document on any web site, or a relative link to only link to a relative location. If you go relative, the value you pass in should be the relative path from the destination directory (specified with the -d option) to the directory containing the packages being linked to. When you specify an absolute link you usually use an HTTP link, but if you want to link to a file system that has no web server, you can use a file link. Use a file link only when everyone who wants to access the generated documentation shares the same file system. And in all cases, on all operating systems, use a slash as the separator β€” whether the URL is absolute or relative, and https:, http:, or file: as specified in the URL Memo: Uniform Resource Locators [http://www.ietf.org/rfc/rfc1738.txt].

-link https://<host>/<directory>/<directory>/.../<name>
-link http://<host>/<directory>/<directory>/.../<name>
-link file://<host>/<directory>/<directory>/.../<name>
-link <directory>/<directory>/.../<name>
  • --link-modularity-mismatch (warn|info) β€” tells the tool how to react when external documentation has the wrong modularity (like, non-modular documentation for a modular library, or the reverse case, messy πŸ’€). Pass warn to report it as a warning, or info to just get a message. The default behavior is to report a warning.
  • -linkoffline url1 url2 β€” a variation of -link, bestie. Both create links to javadoc-generated documentation for externally referenced classes, but this one's for the messy situations. You can specify multiple -linkoffline options in one javadoc tool run 🫢

Use -linkoffline when:

  • You're linking to a document on the web that the javadoc tool can't access through a web connection
  • The package-list or element-list file of the external document either isn't accessible or doesn't exist at the URL location, but does exist at a different location and can be specified by either the package-list or element-list file (typically local)
Note: yep, again β€” the package-list and element-list files are generated by the javadoc tool when generating the API documentation and should not be modified by the user. Don't touch 🌸

If url1 is accessible only on the World Wide Web, then -linkoffline removes the constraint that the javadoc tool must have a web connection to generate documentation. Free at last 😭

Another use of -linkoffline is as a work-around to update documents. After you've run the javadoc tool on a full set of packages or modules, you can run it again on a smaller set of changed packages or modules, so the updated files can be inserted back into the original set. Chef's kiss.

For example, -linkoffline takes two arguments: the first is the string to be embedded in the <a href> links, and the second tells the javadoc tool where to find either the package-list or element-list file.

The url1 or url2 value is the absolute or relative URL of the directory that contains the external javadoc-generated documentation you want to link to. When relative, the value should be the relative path from the destination directory (specified with the -d option) to the root of the packages being linked to. See url in the -link option πŸ‘‘

  • --link-platform-properties url β€” points at a properties file used to configure links to platform documentation. The url argument is expected to point to a properties file containing one or more entries in this exact format, where <version> is the platform version as passed to the --release or --source option and <url> is the base URL of the corresponding platform API documentation:
doclet.platform.docs.<version>=<url>

For instance, a properties file containing URLs for releases 15 to 17 might contain the following lines:

doclet.platform.docs.15=https://example.com/api/15/
doclet.platform.docs.16=https://example.com/api/16/
doclet.platform.docs.17=https://example.com/api/17/

If the properties file doesn't contain an entry for a particular release, no platform links are generated. Simple as that ✨

  • -linksource β€” creates an HTML version of each source file (with line numbers, cute) and adds links to them from the standard HTML documentation. Links get created for classes, interfaces, constructors, methods, and fields whose declarations are in a source file. Otherwise, no links β€” like for default constructors and generated classes. Nothing to link, nothing to see.
⚠️ Heads up: this option exposes all private implementation details in the included source files, including private classes, private fields, and the bodies of private methods β€” regardless of the -public, -package, -protected, and -private options. Unless you also use the -private option, not all private classes or interfaces are accessible through links. So like, be aware πŸ’€

Each link appears on the name of the identifier in its declaration. For example, the link to the source code of the Button class would be on the word Button:

public class Button extends Component implements Accessible

And the link to the source code of the getLabel method in the Button class is on the word getLabel:

public String getLabel()
  • --main-stylesheet file or -stylesheetfile file β€” specifies the path of an alternate stylesheet file containing the definitions for the CSS styles used in the generated documentation. This one lets you override the default πŸŽ€ If you don't specify the option, the javadoc tool creates and uses a default stylesheet. The file name can be any name and isn't restricted to stylesheet.css. Also, --main-stylesheet is the preferred form, so use that one, bestie.

Command-line example:

javadoc --main-stylesheet main_stylesheet.css pkg_foo
  • -nocomment β€” suppresses the entire comment body, including the main description and all tags, and generates only declarations. This lets you reuse source files that were originally intended for a different purpose, so you can produce skeleton HTML documentation during the early stages of a new project. Skeleton docs era πŸ¦‹
  • -nodeprecated β€” prevents the generation of any deprecated API in the documentation. It does what the -nodeprecatedlist option does, and it doesn't generate any deprecated API throughout the rest of the documentation. Super useful when you're writing code and don't want to be distracted by the deprecated stuff. Out of sight, out of mind πŸ™ˆ
  • -nodeprecatedlist β€” prevents the generation of the file containing the list of deprecated APIs (deprecated-list.html) and the link in the navigation bar to that page. The javadoc tool continues to generate the deprecated API throughout the rest of the document though β€” it just hides the list. Useful when your source code contains no deprecated APIs and you want the navigation bar cleaner. Aesthetic ✨
  • -nohelp β€” omits the HELP link in the navigation bar at the top of each page of output. Bye bestie πŸ‘‹
  • -noindex β€” omits the index from the generated documents. The index is produced by default, just so you know.
  • -nonavbar β€” prevents the generation of the navigation bar, header, and footer that are usually found at the top and bottom of the generated pages. Got it? Kay.

The -nonavbar option has no effect on the -bottom option. And it's useful when you're interested only in the content and have no need for navigation β€” like when you're converting the files to PostScript or PDF for printing only. Printing girls rise up πŸŽ€

  • --no-platform-links β€” prevents the generation of links to platform documentation. Those links are generated by default, so this is the opt-out 🫢
  • -noqualifier name1,name2... β€” excludes the list of qualifiers from the output. The package name gets removed from places where class or interface names appear. For historical reasons, : can be used anywhere in the argument as a separator instead of ,. Weird but true, iykyk.

The following example omits all package qualifiers: -noqualifier all.

The following example omits java.lang and java.io package qualifiers: -noqualifier java.lang:java.io.

The following example omits package qualifiers starting with java and com.sun subpackages, but not javax: -noqualifier java.*:com.sun.*.

Where a package qualifier would appear due to the previous behavior, the name can be suitably shortened. And this rule is in effect whether or not the -noqualifier option is used. Sneaky but slay πŸ’…

  • -nosince β€” omits from the generated documents the Since sections associated with the @since tags. No since for you πŸ¦‹
  • -notimestamp β€” hides the time stamp that normally lurks in an HTML comment near the top of every generated page πŸ™ˆ. Honestly? Kind of iconic for diffing: run javadoc on two source bases and diff them, and without this you'd get a diff on every single page just because the clock ticked πŸ•°οΈ. Heads up tho β€” the time stamp also includes the javadoc tool release number, so that's part of what you're hiding.
  • -notree β€” no class and interface hierarchy pages for you, bestie 🚫🌳. Those are the pages you get by clicking the Tree button in the navigation bar. The hierarchy is produced by default, so this is you actively choosing chaos-free output.
  • --override-methods (detail|summary) β€” says where to document overridden methods: in the detail sections or the summary sections. Default is detail, no cap.
  • -overview filename β€” tells javadoc to go grab the overview documentation text from the source file you name in filename and drop it on the Overview page (overview-summary.html) ✨. A relative path in that file name is relative to the current working directory.

You can literally name the file whatever and put it wherever your heart desires πŸ’–, but the classic move is calling it overview.html and parking it in the source tree at the directory that holds the topmost package directories. Why? Because in that spot you don't need a path at all when documenting packages β€” the -sourcepath option is already pointing at that file 🎯.

  • Linux and macOS: say your source tree for the java.lang package is src/classes/java/lang/ β€” then you'd put the overview file at src/classes/overview.html.
  • Windows: say your source tree for the java.lang package is src\classes\java\lang\ β€” then you'd put the overview file at src\classes\overview.html.
Important vibe check: the overview page only gets created when you pass two or more package names to the javadoc tool. And the title on that overview page is set by -doctitle.
  • -serialwarn β€” generates compile-time warnings for missing @serial tags πŸ‘€. By default, Javadoc generates no serial warnings at all. Flip this on to actually see them, which helps you properly document default serializable fields and writeExternal methods. Future you says thank you 🫢.
  • --since *release(,release)** β€” generates documentation for APIs that were added or newly deprecated in the releases you list πŸ“…. Multiple releases? Comma-separate them, bestie.

Here's the tea: if the @since tag in the javadoc comment of a documented element matches a release you passed as an option argument, info about that element and the release it was added in gets included on a "New API" page.

And if the "Deprecated API" page is being generated and the since element of the java.lang.Deprecated annotation of a documented element matches a release in your option arguments, info about the release it was deprecated in gets added to the "Deprecated API" page.

Releases are compared using case-sensitive string comparison. Capital letters matter, periodt πŸ’….

  • --since-label text β€” the text used in the heading of the "New API" page πŸŽ€. It can carry info about the releases covered on the page, e.g. "New API in release 2.0", or "New API since release 1".
  • --snippet-path snippetpathlist β€” the search paths for finding files for external snippets πŸ”. snippetpathlist can hold multiple paths, separated by the platform path separator (; on Windows, : on other platforms). The Standard Doclet first searches the snippet-files subdirectory in the package containing the snippet, and then searches all the directories in the list you gave it.
  • -sourcetab tab-length β€” how many spaces each tab counts for in the source. That's it, that's the whole option πŸŽ€.
  • --spec-base-url url β€” the base URL for relative URLs in @spec tags, used when generating links to any external specifications 🌐. It can be an absolute URL, or a relative URL β€” and if it's relative, it gets evaluated relative to the base directory of the generated output files. Default value is equivalent to {@docRoot}/../specs.
  • -splitindex β€” splits the index file into multiple files, alphabetically, one file per letter πŸ…°οΈπŸ…±οΈπŸ…², plus a file for any index entries that start with non-alphabetical symbols. Organized queen behaviour.
  • -tag name:locations:header β€” sets up single-argument custom tags 🏷️. Real talk: for the javadoc tool to spell-check tag names, it's important that you include a -tag option for every custom tag present in the source code β€” disabling (with X) the ones that aren't being output in the current run. The colon (:) is always the separator. Need a literal colon in the tag name? Escape it with a backward slash (\).

The -tag option outputs the tag heading, header, in bold, followed on the next line by the text from its single argument. Just like any block tag, the argument text can contain inline tags, which also get interpreted ✨. The output is similar to standard one-argument tags such as @return and @author. Omit a header value and the name becomes the heading.

locations is a list of characters saying which kinds of declarations the tag may be used in, and you can use uppercase or lowercase:

  • A: all declarations
  • C: constructors
  • F: fields
  • M: methods
  • O: the overview page and other documentation files in doc-files subdirectories
  • P: packages
  • S: modules
  • T: types (classes and interfaces)
  • X: nowhere β€” the tag is disabled and will be ignored πŸ’€

The order you give tags on the command line is the order they appear in the generated output. And you can slot standard tags into that order by using the -tag option with no locations or header β€” chef's kiss ordering control πŸ‘‘

  • -taglet class β€” the fully qualified name of the taglet used to generate the documentation for that tag. Use the fully qualified name for the class value. This taglet also defines how many text arguments the custom tag has β€” it accepts those arguments, processes them, and generates the output πŸ’«.

Taglets are useful for block or inline tags. They can have any number of arguments and implement custom behavior, like making text bold, formatting bullets, writing text out to a file, or starting other processes. But here's the limit, and it's real: taglets can only determine where a tag should appear and in what form. Every other decision is made by the doclet. A taglet can't do things like remove a class name from the list of included classes. It can execute side effects though β€” printing the tag's text to a file, triggering another process, that kind of main character energy. Use the -tagletpath option to specify the path to the taglet.

This example inserts the To Do taglet after Parameters and ahead of Throws in the generated pages:

-taglet com.sun.tools.doclets.ToDoTaglet
-tagletpath /home/taglets
-tag return
-tag param
-tag todo
-tag throws
-tag see

Alternately you can use the -taglet option in place of its -tag option β€” but ngl that might be difficult to read πŸ™ˆ.

  • -tagletpath tagletpathlist β€” the search paths for finding taglet class files πŸ”Ž. tagletpathlist can contain multiple paths separated by the platform path separator (; on Windows, : on other platforms). The javadoc tool searches all subdirectories of the specified paths.
  • -top html-code β€” the text that goes at the top of each output file β¬†οΈβœ¨.
  • -use β€” creates class and package usage pages, one Use page for each documented class and package πŸ”₯. The page describes what packages, classes, methods, constructors and fields use any API of the specified class or package.

Given class C, things that use class C would include subclasses of C, fields declared as C, methods that return C, and methods and constructors with parameters of type C. For example, you can look at the Use page for the String type β€” because the getName method in the java.awt.Font class returns type String, the getName method uses String and so the getName method appears on the Use page for String 🧡.

This documents only uses of the API, not the implementation. So when a method uses String in its implementation but doesn't take a string as an argument or return a string, that isn't considered a use of String. To access the generated Use page, go to the class or package and click the Use link in the navigation bar πŸ–±οΈ.

  • -version β€” includes the version text in the generated docs. This text is omitted by default. Wanna know what version of the javadoc tool you're using? That's the -J-version option, bestie πŸ’œ.
  • -windowtitle title β€” the title placed in the HTML <title> tag πŸͺŸ. The text you specify in the title tag appears in the window title and in any browser bookmarks (favorite places) that someone creates for this page.
Keep HTML tags out of this title β€” a browser won't interpret them correctly πŸ™…. Use escape characters on any internal quotation marks within the title tag.

If the -windowtitle option is omitted, then the javadoc tool uses the value of the -doctitle option for the -windowtitle option. Example: javadoc -windowtitle "My Library" com.mypackage.


✨ Extra Options for the Standard Doclet ✨

Okay so these next ones are extra options provided by the Standard Doclet, and they are subject to change without notice ⚠️ β€” so don't get too attached. They're also less commonly used, or otherwise regarded as advanced. Advanced bestie hours πŸ§šπŸ’…

  • --date date-and-time β€” sets the timestamp stamped onto the pages you generate, and it's gotta be in ISO 8601 format (the whole date-and-time-for-mat.html situation, iykyk). Two things to know, bestie: the value must be within 10 years of the current date and time, and specifying both -notimestamp and --date is literally an error. Why would you even want this? Because pinning a specific value means your generated docs can be part of a reproducible build (that's reproducible-builds.org, slay). Don't pass the option at all and the default is just the current date and time. Like so:
javadoc --date 2022-02-01T17:41:59-08:00 mypackage
  • --legal-notices (default|none|directory) β€” tells javadoc where to copy legal files from, into the generated docs. Leave the option off entirely, or use it with the value default, and the files get copied from the default location. Use it with the value none and nothing gets copied at all, zero files, nada. Any other argument? That gets interpreted as a directory to copy the legal files from. πŸŽ€
  • --no-frames β€” this one's a no-op, a total vibe that does nothing. It's just retained for backwards compatibility. Not me keeping a flag around purely out of nostalgia πŸ’€
  • -Xdoclint β€” turns on the recommended checks for problems in your documentation comments. And surprise: it's enabled by default. Turn it off with -Xdoclint:none. More deets in DocLint, below.
  • *-Xdoclint:flag,flag,...* β€” enable or disable specific checks for different kinds of issues in documentation comments. Each flag can be one of all, none, or [-]group, where group has one of these values: accessibility, html, missing, reference, syntax. More on those values in DocLint Groups.

When you're specifying two or more flags you've got options, bestie: either one single -Xdoclint:... option listing all the flags you want, or multiple options each carrying one or more flag. Both work. For example, either of these commands checks for the HTML, syntax, and accessibility issues in the file MyFile.java:

javadoc -Xdoclint:html -Xdoclint:syntax -Xdoclint:accessibility MyFile.java
javadoc -Xdoclint:html,syntax,accessibility MyFile.java

And here's how you change what DocLint actually reports:

  • -Xdoclint:none β€” disables all checks
  • -Xdoclint:group β€” enables group checks
  • -Xdoclint:all β€” enables all groups of checks
  • -Xdoclint:all,-group β€” enables all checks except group checks

For more details, see DocLint.

  • -Xdoclint/package:[-]packages β€” enables or disables checks in specific packages. packages is a comma separated list of package specifiers. A package specifier is either a qualified name of a package, or a package name prefix followed by *, which expands to all subpackages of the given package. Prefix the package specifier with - to disable checks for those packages. For more details, see DocLint.
  • -Xdocrootparent url β€” replaces all @docRoot items followed by /.. in documentation comments with url. Swapsies ✨

πŸ” DOCLINT πŸ”

DocLint is the girl who checks for possible problems in your documentation comments. Problems get reported as warnings or errors depending on how serious they are. For example, a missing comment might just be bad style that deserves a warning, but a link to an unknown Java declaration is way more serious and deserves an error, periodt. Problems are organized into groups, and you can use options to enable or disable messages in one or more groups. And inside the source code itself, messages in one or more groups can be suppressed using @SuppressWarnings annotations.

When it's invoked from javadoc, DocLint by default checks all comments used in the generated documentation. Which means it relies on the other command-line options to figure out which declarations β€” and which corresponding documentation comments β€” will actually be included. Heads up: this may mean even comments on some private members of serializable classes get checked too, if those members need to be documented in the generated Serialized Forms page. πŸ™ˆ

In contrast, when DocLint is invoked from javac, it solely relies on the various -Xdoclint... options to determine which documentation comments to check. Different energy entirely.

DocLint doesn't attempt to fix invalid input β€” it just reports it. No fixing, only reading you to filth πŸ’…

Note: DocLint doesn't guarantee the completeness of these checks. In particular, it isn't a full HTML compliance checker. The goal is just to report common errors in a convenient manner.

🌸 Groups 🌸

The checks DocLint performs are organized into groups. The warnings and errors in each group can be enabled or disabled with command-line options, or suppressed with @SuppressWarnings annotations. The groups are:

  • accessibility β€” checks for issues related to accessibility. For example, no alt attribute specified in an <img> element, or no caption or summary attributes specified in a <table> element.

These issues are reported as errors if a downstream validation tool might be expected to report an error in the files generated by javadoc.

For reference, see the Web Content Accessibility Guidelines (w3.org/WAI/standards-guidelines/wcag/).

  • html β€” detects common high-level HTML issues. For example, putting block elements inside inline elements, or not closing elements that require an end tag.

These issues are reported as errors if a downstream validation tool might be expected to report an error in the files generated by javadoc.

For reference, see the HTML Living Standard (html.spec.whatwg.org/multipage/).

  • missing β€” checks for missing documentation comments or tags. For example, a missing comment on a class declaration, or a missing @param or @return tag in the comment for a method declaration.

Issues related to missing items are typically reported as warnings, because they're unlikely to be reported as errors by downstream validation tools that may be used to check the output generated by javadoc.

  • reference β€” checks for issues relating to the references to Java API elements from documentation comment tags. For example, the reference in @see or {@link ...} cannot be found, or a bad name is given for @param or @throws.

These issues are typically reported as errors, because while the issue may not cause problems in the generated files, the author has likely made a mistake that will lead to incorrect or unexpected documentation. 😭

  • syntax β€” checks for low-level syntactic issues in documentation comments. For example, unescaped angle brackets (< and >) and ampersands (&) and invalid documentation comment tags.

These are typically reported as errors, because the issues may lead to incorrect or unexpected documentation.

🀫 Suppressing Messages 🀫

DocLint checks for and recognizes two strings that may be present in the arguments for an @SuppressWarnings annotation:

  • doclint
  • doclint:LIST

where LIST is a comma-separated list of one or more of accessibility, html, missing, syntax, reference.

The names in LIST are the same group names supported by the command-line -Xdoclint option for javac and javadoc. (This is the same convention honored by the javac -Xlint option and the corresponding names supported by @SuppressWarnings.) 🫢

The names in LIST can equivalently be specified in separate arguments of the annotation. For example, these two are equivalent:

  • @SuppressWarnings("doclint:accessibility,missing")
  • @SuppressWarnings("doclint:accessibility", "doclint:missing")

When DocLint detects an issue in a documentation comment, it checks for the presence of @SuppressWarnings on the associated declaration and on all lexically enclosing declarations. The issue will be ignored if any such annotation is found containing the simple string doclint, or the longer form doclint:LIST where LIST contains the name of the group for the issue.

Note: as with other uses of @SuppressWarnings, using the annotation on a module or package declaration only affects that declaration; it does not affect the contents of the module or package in other source files.

All messages related to an issue are suppressed by the presence of an appropriate @SuppressWarnings annotation β€” and yes, that includes errors as well as warnings.

Note: it's only possible to suppress messages. If an annotation of @SuppressWarnings("doclint") is given on a top-level declaration, all DocLint messages for that declaration and any enclosed declarations will be suppressed; it is not possible to selectively re-enable messages for issues in enclosed declarations. Once it's silenced, it's silenced πŸ’€

βš–οΈ Comparison with downstream validation tools βš–οΈ

DocLint is a utility built into javac and javadoc that checks the content of documentation comments, as found in source files. Downstream validation tools, on the other hand, validate the output generated from those documentation comments by javadoc and the Standard Doclet. There's some overlap in functionality, but the two mechanisms are different and each has its own strengths and weaknesses:

  • Downstream validation tools can check the end result of any generated documentation, exactly as it will be seen by the end user. That includes content from all sources β€” documentation comments, the Standard Doclet itself, user-provided taglets, and content supplied via command-line options. Because such tools analyze complete HTML pages, they can do more complete checks than DocLint can. But when a problem is found in the generated pages, it can be harder to track down exactly where in the build pipeline the problem needs to be fixed. πŸ”₯
  • DocLint checks the content of documentation comments, in source files. That makes it super easy to identify the exact position of any issues found. DocLint can also detect some semantic errors in documentation comments that downstream tools cannot, like missing comments, using an @return tag in a method returning void, or an @param tag describing a non-existent parameter. But by its nature, DocLint cannot report on problems such as missing links, or errors in user-provided custom taglets, or problems in the Standard Doclet itself. It also cannot reliably detect errors in documentation comments at the boundaries between content in a documentation comment and content generated by a custom taglet. It's giving different tools for different jobs, and that's iconic πŸ’…

And that's the whole page, bestie β€” you ate that πŸ“ This particular flavor of the manual is from JDK 21, dated 2023, under the name JAVADOC(1). Go forth and document, queen πŸ‘‘βœ¨

πŸ“¦ where this page comes from