JAVADOC(1)
π¦ JAVADOC(1) β the javadoc command, explained by your favorite Unix bestie π¦
okay so welcome to JAVADOC(1), from the JDK Commands family β literally the tool that turns your Java source files into pretty HTML API docs. she's iconic, she's underrated, and she's about to be your new obsession. let's get into it π
β¨ NAME β¨
javadoc β generates HTML pages of API documentation from Java source files. no cap, that's her whole job π
πΈ SYNOPSIS πΈ
javadoc [options] [packagenames] [sourcefiles] [@files]
optionsβ the command-line options, separated by spaces. obvi. see Standard javadoc Options, Extra javadoc Options, Standard Options for the Standard Doclet, and Extra Options for the Standard Doclet below (well, in the parts that follow) π«Άpackagenamesβ the names of the packages you want documented, separated by spaces, likejava.lang java.lang.reflect java.awt. and if you also wanna document the subpackages, use the-subpackagesoption to specify the packages. by default,javadoclooks for those packages in the current directory and its subdirectories β use-sourcepathto give her the list of directories to search instead πsourcefilesβ the names of the Java source files you want documented, separated by spaces, likeClass.java Object.java Button.java. by defaultjavadoclooks for those classes in the current directory, but bestie you can absolutely give her the full path to the class file and use wildcard characters, like/home/src/java/awt/Graphics*.java. you can also specify the path relative to the current directory β¨@filesβ the names of files that contain a list ofjavadoctool options, package names, and source file names, in any order. little bundle files, love that for us π¦
π DESCRIPTION π
so the javadoc tool parses the declarations and the 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 implicitly declared classes (but not anonymous inner classes, we don't do those π), interfaces, constructors, methods, and fields. you can use javadoc to generate the API documentation or the implementation documentation for a set of source files.
you can run javadoc on entire packages, individual source files, or both, because she's flexible like that π. when you're documenting whole 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're documenting individual source files, just pass in a list of Java source file names. easy.
β οΈ Conformance β οΈ
real talk, this part matters. read it. π
The Standard Doclet does not validate the content of documentation comments for conformance, and it does not attempt to correct any errors in documentation comments either. 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's 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 [https://www.w3.org/TR/html5/infrastructure.html#conformance-requirements] in the HTML5 Specification. for more details on security issues related to web pages, see the Open Web Application Security Project (OWASP) [https://www.owasp.org] page. go read them, i'm serious π§
π 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. cute, right? π
π 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:
--add-modules-bootclasspath--class-path,-classpath, or-cp--enable-preview-encoding-extdirs--limit-modules--module--module-pathor-p--module-source-path--release--sourceor-source--source-pathor-sourcepath--system--upgrade-module-path
and these next ones are the core javadoc options that are not equivalent to a corresponding javac option β these are the homegrown ones, the main characters π
-breakiteratorβ computes the first sentence withBreakIterator. that first sentence gets copied to the package, class, or member summary and to the alphabetic index. theBreakIteratorclass is used to determine the end of a sentence for all languages except English. and here's the tea:- 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
-breakiteratoroption 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. so dramatic π
- English default sentence-break algorithm --- stops at a period followed by a space or an HTML block tag, such as
-docletclass β generates output by using an alternate doclet. use the fully qualified name. this doclet defines the content and formats the output. if-docletisn't used, then thejavadoctool uses the standard doclet for generating the default HTML format. this class must contain thestart(Root)method. the path to this starting class is defined by the-docletpathoption π¦-docletpathpath β specifies where to find doclet class files (specified with-doclet) 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. ifclasspathlistcontains 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. slay π-excludepkglist β unconditionally excludes the specified packages and their subpackages from the list formed by-subpackages. and i mean unconditionally β it excludes those packages even when they would otherwise be included by some earlier or later-subpackagesoption. she does not care. β
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-requiresvalue β instructs thejavadoctool 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. the whole squad π
--help,-help,-h, or-?β prints a synopsis of the standard options. four whole ways to ask for help, we love options π--help-extraor-Xβ prints a synopsis of the set of extra options.-Jflagβ passesflagdirectly to the Java Runtime Environment (JRE) that runs thejavadoctool. 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-Xmxoption as follows:javadoc -J-Xmx32m -J-Xms32m com.mypackage. be aware that-Xmsis 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 theJand theflag. none. zero. don't do it. π
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)
-localename β specifies the locale that thejavadoctool uses when it generates documentation. the argument is the name of the locale, as described in thejava.util.Localedocumentation, such asen_US(English, United States) oren_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. however β the -locale option doesn't determine the locale of the documentation comment text specified in the source files of the documented classes. important distinction, don't forget it π§
-packageβ shows only package, protected, and public classes and members.-privateβ shows all classes and members. everything. the whole closet. π-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, making them easier to view. it also suppresses the version string. peace and quiet, finally π€«--show-membersvalue β specifies which members (fields or methods) are documented, where value can be any of the following:public--- shows only public membersprotected--- shows public and protected members; this is the defaultpackage--- shows public, protected, and package membersprivate--- shows all members
--show-module-contentsvalue β specifies the documentation granularity of module declarations, where value can beapiorall.--show-packagesvalue β specifies which modules' packages are documented, where value can beexportedorallpackages.
okay that's part one bestie, and there is so much more coming β don't go anywhere π«Άβ¨
--show-typesvalue β tells the tool which kinds of types (classes, interfaces, whatever) actually get documented. value can be any of these, bestie:publicβ only public types get shown β¨protectedβ public and protected types; this is the default, iykykpackageβ public, protected, and package typesprivateβ literally everything, no filter, main character energy
-subpackagessubpkglist β generates docs from source files in the packages you name and recursively in all their subpackages. This one is lowkey iconic when you're adding new subpackages to your source code, because they get picked up automatically, no extra effort π«Ά. Each package argument is any top-level subpackage (likejava) or a fully qualified package (likejavax.swing) and it doesn't need to actually contain source files. Arguments are separated by colons on all operating systems (yes, even Windows, don't fight it). Wild cards aren't allowed. Use-sourcepathto specify where to find the packages. Heads up: this option doesn't process source files that are 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-verbose, messages appear for loading the source files, generating the documentation (one message per source file), and sorting. With-verbose, you also get additional messages that specify the number of milliseconds it takes to parse each Java source file. Timestamps for your parsing era π--versionβ prints version information. Short, sweet, slays.-Werrorβ reports an error if any warnings occur. Zero tolerance policy, we respect it π
Note that if a Java source file contains an implicitly declared class, then that class and its public, protected, and package members will be documented regardless of the options such as--show-types,--show-members,-private,-protected,-package, and-public. If--show-membersis specified with valueprivateor if-privateis used, then all private members of an implicitly declared class will be documented too. So likeβ¦ the implicit class does what it wants. Noted. π
π§© Extra javadoc Options
Note: The additional options for javadoc are subject to change without notice. (Read: don't get too attached, bestie.)
The following additional javadoc options are equivalent to corresponding javac options. See Extra Options in javac for the detailed descriptions of using these options:
--add-exports--add-reads--patch-module-Xmaxerrs-Xmaxwarns
π Standard Options for the Standard Doclet
The following options are provided by the standard doclet. This is where it gets cute β actual styling, actual output, actual vibes.
--add-scriptfile β adds file as an additional JavaScript file to the generated documentation. You can use this option one or more times to specify additional script files. Stack 'em up π§
Command-line example:
javadoc --add-script first_script.js --add-script second_script.js pkg_foo
--add-stylesheetfile β adds file as an additional stylesheet file to the generated documentation. This option can also be used one or more times to specify additional stylesheets included in the documentation. More CSS, more slay πΈ
Command-line example:
javadoc --add-stylesheet new_stylesheet_1.css --add-stylesheet new_stylesheet_2.css pkg_foo
--allow-script-in-commentsβ allow JavaScript in options and comments. That's it, that's the whole thing.-authorβ includes the@authortext in the generated docs. Give the people their credit π-bottomhtml-code β specifies the text to be placed at the bottom of each output file. The text goes at the bottom of the page, underneath the lower navigation bar. It can contain HTML tags and white space, but when it does, the text must be enclosed in quotation marks. Use escape characters for any internal quotation marks within the text.-charsetname β specifies the HTML character set for this document. The 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).
-ddirectory β specifies the destination directory where the javadoc tool saves the generated HTML files. If you omit-d, the files get saved to the current directory. The directory value can be absolute or relative to the current working directory. And good news: the destination directory is automatically created when the javadoc tool runs. Nomkdirneeded, we love convenience β¨- Linux and macOS: for example, the following command generates the documentation for the package
com.mypackageand saves the results in the/user/doc/directory:
- Linux and macOS: for example, the following command generates the documentation for the package
javadoc -d /user/doc/ com.mypackage
- Windows: for example, the following command generates the documentation for the package
com.mypackageand saves the results in the\user\doc\directory:
javadoc -d \user\doc\ com.mypackage
-docencodingname β specifies the encoding of the generated HTML files. The name should be a preferred MIME name as specified in the IANA Registry, Character Sets (http://www.iana.org/assignments/character-sets).
Three options are 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 an output encoding option are used in a single encoding command. If you specify both input and output encoding options in a command, they must be the same value. If you specify neither output option, it defaults to the input encoding. Rules are rules π
For example:
javadoc -docencoding "iso-8859-1" mypackage
-docfilessubdirsβ recursively copies doc-file subdirectories. Enables deep copying ofdoc-filesdirectories. Subdirectories and all contents are recursively copied to the destination. For example, the directorydoc-files/example/imagesand all of its contents are copied. The-excludedocfilessubdiroption can be used to exclude specific subdirectories. Go deep or go home π¦-doctitlehtml-code β specifies the title to place near the top of the overview summary file. The text specified in the title tag is 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.-excludedocfilessubdirname1,name2... β excludes any subdirectories with the given names when recursively copying doc-file subdirectories. See-docfilessubdirs. For historical reasons,:can be used anywhere in the argument as a separator instead of,. (Yes,:. Historically. Don't ask. π)-footerhtml-code β specifies the footer text to be placed at the bottom of each output file. The html-code value is placed to the right of the lower navigation bar. The html-code value can contain HTML tags and white space, but when it does, it must be enclosed in quotation marks. Use escape characters for any internal quotation marks within a footer.-groupname p1,p2... β group the specified packages together in the Overview page. For historical reasons,:can be used as a separator anywhere in the argument instead of,. Organize your faves into a group chat π«Ά-headerhtml-code β specifies the header text to be placed at the top of each output file. The header is placed 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.-helpfilefilename β 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 filehelp-doc.htmlthat is hard-coded in the javadoc tool. This option lets you override the default. The filename can be any name and isn't restricted tohelp-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 nothing. It is vibes only. π--javafxor-javafxβ enables JavaFX functionality. This option is enabled by default if the JavaFX library classes are detected on the module path.-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 are identical to the class name. For example, the classStringstarts with these keywords:-link urlβ bestie, this one creates links to javadoc-generated docs of externally referenced classes β¨ The url argument is the absolute or relative URL of the directory that contains that external javadoc-generated documentation. And yes, you can stack multiple-linkoptions in a single javadoc tool run to link to multiple documents β go off π
Okay so rules: either a package-list or an element-list file must be in this url directory (otherwise, use the -linkoffline option, we'll get there).
Note: thepackage-listandelement-listfiles are generated by the javadoc tool when generating the API documentation and should not be modified by the user. Not you. Hands off π«Ά
When you use the javadoc tool to document packages, it uses the package-list file to determine the packages declared in an API. When you generate API documents for modules, the javadoc tool uses the element-list file to determine the modules and packages declared in an API.
The javadoc tool reads the names from the appropriate list file and then links to the packages or modules at that URL.
When the javadoc tool runs, the url value is copied into the <A HREF> links that are created. So like β url must be the URL to the directory, not to a file. Directory. Not file. Got it? π
You can use an absolute link for url to enable your documents to link to a document on any web site, or you can use a relative link to link only to a relative location. If you use a relative link, then 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. However, if you want to link to a file system that has no web server, then 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. In all cases, and 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)β decides the vibe check for external docs with the wrong modularity, like non-modular documentation for a modular library, or the reverse case π Should it be reported as a warning (warn) or just a message (info)? The default behavior is to report a warning. So by default it will yell at you, bestie.-linkoffline url1 url2β this is literally just a variation of the-linkoption π They both create links to javadoc-generated documentation for externally referenced classes. And yeah, you can specify multiple-linkofflineoptions in a single javadoc tool run.
Use the -linkoffline option when:
- Linking to a document on the web that the javadoc tool can't access through a web connection
- The
package-listorelement-listfile 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 thepackage-listorelement-listfile (typically local).
Note: thepackage-listandelement-listfiles are generated by the javadoc tool when generating the API documentation and should not be modified by the user. Again. Still. Forever π
If url1 is accessible only on the World Wide Web, then the -linkoffline option removes the constraint that the javadoc tool must have a web connection to generate documentation. Iconic loophole behavior, honestly.
Another use of the -linkoffline option is as a work-around to update documents. After you have run the javadoc tool on a full set of packages or modules, you can run the javadoc tool again on a smaller set of changed packages or modules, so that the updated files can be inserted back into the original set.
For example β and this is the part where you gotta pay attention because there's two arguments β the -linkoffline option takes two arguments. The first is for 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 that 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. Same energy, different flag β¨
--link-platform-properties urlβ specifies 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 with this 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 does not contain an entry for a particular release, no platform links are generated. Like, none. Zero. Nothing. π
-linksourceβ creates an HTML version of each source file (with line numbers!) and adds links to them from the standard HTML documentation π₯ Links are created for classes, interfaces, constructors, methods, and fields whose declarations are in a source file. Otherwise, links aren't created β such as for default constructors and generated classes.
Heads up bestie, 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-privateoptions. Unless you also use the-privateoption, not all private classes or interfaces are accessible through links. So like... know what you're doing π
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
The link to the source code of the getLabel method in the Button class is on the word getLabel:
public String getLabel()
--main-stylesheet fileor-stylesheetfile fileβ specifies the path of an alternate stylesheet file that contains the definitions for the CSS styles used in the generated documentation π This option lets you override the default. If you do not specify the option, the javadoc tool will create and use a default stylesheet. The file name can be any name and isn't restricted tostylesheet.css. The--main-stylesheetoption is the preferred form, so use that one, mmkay? π
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 option lets you reuse source files that were originally intended for a different purpose so that you can produce skeleton HTML documentation during the early stages of a new project. Skeleton docs era, we love to see it π¦-nodeprecatedβ prevents the generation of any deprecated API in the documentation π« This does what the-nodeprecatedlistoption does, and it doesn't generate any deprecated API throughout the rest of the documentation. This is useful when writing code when you don't want to be distracted by the deprecated code. Out of sight, out of mind, fr fr.-nodeprecatedlistβ prevents the generation of the file that contains 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 β this one's just about the list page. This is useful when your source code contains no deprecated APIs, and you want to make the navigation bar cleaner. Clean navbar aesthetic β¨-nohelpβ omits the HELP link in the navigation bar at the top of each page of output. That's it. That's the whole thing. Bye help link π-noindexβ omits the index from the generated documents. The index is produced by default, so this is you actively choosing chaos / minimalism π-nonavbarβ prevents the generation of the navigation bar, header, and footer, that are usually found at the top and bottom of the generated pages πΈ The-nonavbaroption has no effect on the-bottomoption β important!! The-nonavbaroption is useful when you are interested only in the content and have no need for navigation, such as when you are converting the files to PostScript or PDF for printing only π--no-platform-linksβ prevents the generation of links to platform documentation. These links are generated by default. So this is the off switch, you're welcome π-noqualifier name1,name2...β excludes the list of qualifiers from the output; the package name is removed from places where class or interface names appear βοΈ For historical reasons,:can be used anywhere in the argument as a separator instead of,.
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.*.
Note the wildcards bestie β java.* catches the java family, com.sun.* catches the subpackages, and javax is left completely alone. Sneaky but correct π
Where a package qualifier would appear because of the previous behavior, the name can be suitably shortened. This rule is in effect whether or not the -noqualifier option is used. π
-nosinceβ dips out on the Since sections that go with the@sincetags. They just... don't show up in the generated docs. π-notimestampβ suppresses the time stamp, which is hidden in an HTML comment in the generated HTML near the top of every page. Lowkey the most useful option ever if you're the diffing type: run thejavadoctool on two source bases and diff them, and this stops the time stamps from causing a diff β because otherwise you'd get a diff on literally every single page π. Heads up: the time stamp includes thejavadoctool release number.-notreeβ omits the class and interface hierarchy pages from the generated documents. Those are the pages you reach with the Tree button in the navigation bar, bestie. The hierarchy is produced by default, so this one's the "actually, no" button. π³--override-methods (detail|summary)β documents overridden methods in the detail or the summary sections. The default isdetail.-overview filenameβ tells thejavadoctool to go grab the text for the overview documentation from the source file you named in filename and slap it onto the Overview page (overview-summary.html). A relative path you give with the file name is relative to the current working directory. ποΈ
You can name filename anything you want and put it anywhere you want on the path β but the classic move is naming it overview.html and dropping it in the source tree at the directory that contains the topmost package directories. In that spot you don't need a path at all when documenting packages, because the -sourcepath option points to this file. Iconic placement. π
- Linux and macOS: for example, if the source tree for the
java.langpackage issrc/classes/java/lang/, then you could place the overview file atsrc/classes/overview.html. - Windows: for example, if the source tree for the
java.langpackage issrc\classes\java\lang\, then you could place the overview file atsrc\classes\overview.html.
Real talk: the overview page is created only when you pass two or more package names to thejavadoctool. And the title on the overview page is set by-doctitle.
-serialwarnβ generates compile-time warnings for missing@serialtags. By default, Javadoc generates no serial warnings at all. Use this option to actually display them, which helps you properly document default serializable fields andwriteExternalmethods. π₯--since release(,release)*β generates documentation for APIs that were added or newly deprecated in the specified releases.
If the @since tag in the javadoc comment of an element in the documented source code matches a release you passed as an option argument, then info about the element and the release it was added in gets included in a "New API" page. β¨
If the "Deprecated API" page is generated and the since element of the java.lang.Deprecated annotation of a documented element matches a release in the option arguments, then info about the release the element was deprecated in gets added to the "Deprecated API" page.
Releases are compared using case-sensitive string comparison. So yes, case matters. π
--since-label textβ specifies the text to use in the heading of the "New API" page. This may contain information about the releases covered in the page, e.g."New API in release 2.0", or"New API since release 1".--snippet-path snippetpathlistβ specifies the search paths for finding files for external snippets. The snippetpathlist can contain multiple paths by separating them with the platform path separator (;on Windows;:on other platforms). The Standard Doclet first searches thesnippet-filessubdirectory in the package containing the snippet, and then searches all the directories in the given list. π¦-sourcetab tab-lengthβ specifies the number of spaces each tab uses in the source.--spec-base-url urlβ specifies the base URL for relative URLs in@spectags, to be used when generating links to any external specifications. It can either be an absolute URL, or a relative URL β in which case it's evaluated relative to the base directory of the generated output files. The 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. Little index glow-up. π-tag name:locations:headerβ specifies single argument custom tags. Okay important bit: for thejavadoctool to spell-check tag names, it's important to include a-tagoption for every custom tag that's present in the source code β disabling (withX) those that aren't being output in the current run. The colon (:) is always the separator. To include a 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. Similar to any block tag, the argument text can contain inline tags, which are also interpreted. The output is similar to standard one-argument tags, such as the @return and @author tags. Omitting a header value causes the name to be the heading.
locations is a list of characters specifying the kinds of declarations in which the tag may be used. The following characters may be used, in either uppercase or lowercase:
A: all declarationsC: constructorsF: fieldsM: methodsO: the overview page and other documentation files indoc-filessubdirectoriesP: packagesS: modulesT: types (classes and interfaces)X: nowhere β the tag is disabled, and will be ignored π
The order in which tags are given on the command line will be used as the order in which the tags appear in the generated output. And yes β you can include standard tags in the order given on the command line by using the -tag option with no locations or header.
-taglet classβ specifies the fully qualified name of the taglet used in generating the documentation for that tag. Use the fully qualified name for the class value. This taglet also defines the number of text arguments that the custom tag has. The taglet 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, such as making text bold, formatting bullets, writing out the text to a file, or starting other processes.
Fr fr, know the limits: taglets can only determine where a tag should appear and in what form. All other decisions are made by the doclet. A taglet can't do things such as remove a class name from the list of included classes. However, it can execute side effects, such as printing the tag's text to a file or triggering another process.
Use the -tagletpath option to specify the path to the taglet. The following 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β specifies the search paths for finding taglet class files. The tagletpathlist can contain multiple paths by separating them with the platform path separator (;on Windows;:on other platforms). Thejavadoctool searches all subdirectories of the specified paths.-top html-codeβ specifies the text to be placed at the top of each output file.-useβ creates class and package usage pages. Includes 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. π
Caveat, bestie: this documents only uses of the API, not the implementation. When a method usesStringin its implementation, but doesn't take a string as an argument or return a string, that isn't considered a use ofString. 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. To find out what version of thejavadoctool you are using, use the-J-versionoption. (Different thing! Don't mix them up β¨)-windowtitle titleβ specifies the title to be placed in the HTML<title>tag. The text specified in the title tag appears in the window title and in any browser bookmarks (favorite places) that someone creates for this page.
This title should not contain any HTML tags, because a browser will not 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. For example, javadoc -windowtitle "My Library" com.mypackage.
π Extra Options for the Standard Doclet π
The following are additional options provided by the Standard Doclet and are subject to change without notice. Additional options are less commonly used or are otherwise regarded as advanced. π«Ά
--date date-and-timeβ picks the exact timestamp that goes on the generated pages, and it's gotta be in ISO 8601 [https://www.iso.org/iso-8601-date-and-time-format.html] format bestie. The value you give has to land within 10 years of right-now (the current date and time), no cap. And heads up: passing both-notimestampand--dateis literally an error, pick a lane π . Giving a specific value is the whole point tho β it means your generated docs can be part of a reproducible build [https://reproducible-builds.org/] β¨. If you don't pass the option at all, the default value is just the current date and time. Example era:
javadoc --date 2022-02-01T17:41:59-08:00 mypackage
--legal-notices (default|none|directory)β tells javadoc where to copy the legal files from for the generated documentation π. If you don't specify the option, or you use it with the valuedefault, the files get copied from the default location. If you use the valuenone, no files get copied at all (ghost mode π»). And literally every other argument? It's interpreted asdirectoryβ the place to copy the legal files from.--no-framesβ ok so this one is a no-op, it does nothing π. It's just hanging around for backwards compatibility. Old flags never die, they just stop doing things.-Xdoclintβ turns on the recommended checks for problems in documentation comments π©Ί. By default, the-Xdoclintoption is enabled already (iconic default behavior). You disable it with the option-Xdoclint:none. For more details, see DocLint.-Xdoclint:flag,flag,...β enable or disable specific checks for different kinds of issues in documentation comments π. Each flag can be one ofall,none, or[-]groupwheregrouphas one of the following values:accessibility,html,missing,reference,syntax. For more details on these values, see DocLint Groups.
When you're specifying two or more flags, you've got options (pun intended): you can either use a single -Xdoclint:... option listing all the desired flags, or you can use multiple options giving one or more flag in each option π«Ά. For example, use either of the following commands to check 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
The following examples illustrate how to change what DocLint 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 π¦.packagesis 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 the specified packages (the little minus sign is doing the "nope, not these" work π ). For more details, see DocLint.-Xdocrootparent urlβ replaces all@docRootitems followed by/..in documentation comments with url π.
π©Ί DOCLINT π©Ί
DocLint is the bestie that checks for possible problems in documentation comments π. Problems may be reported as warnings or errors, depending on their severity. Like, a missing comment may be bad style that deserves a warning, but a link to an unknown Java declaration is way more serious and deserves an error π. Problems are organized into groups, and options can be used to enable or disable messages in one or more groups. And within the source code, messages in one or more groups can be suppressed by using @SuppressWarnings annotations. slay.
When invoked from javadoc, by default DocLint checks all comments that are used in the generated documentation β¨. It thus relies on other command-line options to determine which declarations, and which corresponding documentation comments will be included. Note: this may mean that even comments on some private members of serializable classes will also be checked, if the members need to be documented in the generated Serialized Forms page π.
In contrast, when DocLint is invoked from javac, DocLint solely relies on the various -Xdoclint... options to determine which documentation comments to check.
DocLint doesn't attempt to fix invalid input, it just reports it π’ β it's giving honest friend energy, not glow-up-makeover energy.
Note: DocLint doesn't guarantee the completeness of these checks. In particular, it isn't a full HTML compliance checker. The goal is to just report common errors in a convenient manner. π«
Groups
The checks performed by DocLint 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 as follows:
accessibility--- Checks for issues related to accessibility π. For example, noaltattribute specified in an<img>element, or nocaptionorsummaryattributes specified in a<table>element.
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 [https://www.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.
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 [https://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@paramor@returntag in the comment for a method declaration.
Issues related to missing items are typically reported as warnings because they are 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@seeor{@link ...}cannot be found, or a bad name is given for@paramor@throws.
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. bestie made a typo, and the docs are gonna show it π.
syntax--- Checks for low-level syntactic issues in documentation comments π§. For example, unescaped angle brackets (<and>) and ampersands (&) and invalid documentation comment tags.
Issues 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 π€«:
doclintdoclint: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, the following 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: this includes errors as well as warnings π.
Note: It is 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. no take-backsies, it's all-or-nothing π
.
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 π. In contrast, downstream validation tools can be used to validate the output generated from those documentation comments by javadoc and the Standard Doclet.
Although there is some overlap in functionality, 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, as it will be seen by the end user π. This includes content from all sources, including documentation comments, the Standard Doclet itself, user-provided taglets, and content supplied via command-line options. Because such tools are analyzing complete HTML pages, they can do more complete checks than can DocLint. However, 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 π. This makes it very easy to identify the exact position of any issues that may be found. DocLint can also detect some semantic errors in documentation comments that downstream tools cannot detect, such as missing comments, using an
@returntag in a method returningvoid, or an@paramtag 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.
okay that's the whole page bestie, you made it to the end ππ this one's from JDK 22, dated 2024, and it lives at JAVADOC(1) in the manual β go forth and document your little heart out, no cap β¨π¦π
π¦ where this page comes from
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms