javadoc - Generates HTML pages of API documentation from Java source files.
| Use Case | Command | Description |
|---|---|---|
| Document a package | javadoc -d output_dir com.mypackage | Generate HTML for a package (source must be in corresponding directory) |
| Document with source path | javadoc -d output_dir -sourcepath /src com.mypackage | Specify where to find source files for packages |
| Recurse into subpackages | javadoc -d output_dir -sourcepath /src -subpackages java | Document a package and all its subpackages |
| Exclude packages | javadoc -d output_dir -sourcepath /src -subpackages java -exclude java.net:java.lang | Exclude certain packages from recursive scan |
| Document specific source files | javadoc -d output_dir Class.java Interface.java | Generate docs for explicit list of source files |
| Add window title | javadoc -windowtitle "My API" ... | Set browser window/tab title |
| Link to external docs | javadoc -link http://example.com/api/ ... | Link to other Javadoc output (requires package-list) |
| Set author/version | javadoc -author -version ... | Include @author and @version tags in output |
| Show only public classes | javadoc -public ... | Limit documentation to public members |
| Custom doclet | javadoc -doclet com.example.MyDoclet -docletpath /path ... | Use a custom doclet instead of the standard HTML doclet |
javadoc {packages|source-files} [options] [@argfiles]
packages โ Names of packages to document, separated by spaces, e.g. java.lang java.awt. Use -subpackages to include subpackages.
source-files โ Java source file names, separated by spaces, e.g. Class.java Object.java.
options โ Command-line options (see Options).
@argfiles โ Files containing lists of options, package names, or source file names.
The javadoc command parses declarations and documentation comments in Java source files and produces HTML pages describing the public and protected classes, interfaces, constructors, methods, and fields. You can run it on entire packages, individual source files, or both. When using packages, use -subpackages for recursion or pass explicit package names.
The javadoc command processes files that end in .java and meet these requirements:
.java) is a valid class name.package statement contains the valid package name.Processing Links: During a run, cross-reference links are added for declarations, @see tags, {@link} tags, @throws tags, overrides, summary tables, inheritance trees, and the index. Use -link and -linkoffline to link to external documentation.
Processing Details: The javadoc command produces a complete document each run; it does not do incremental builds. It relies on the Java compiler to load declarations, builds a rich internal representation, and picks up user-supplied documentation from comments. It works on stub files without method bodies, allowing early documentation. It must be able to find all referenced classes (bootstrap, extension, user). See How Classes Are Found.
You can customize output with doclets. The built-in standard doclet generates HTML. Use -doclet to specify a custom doclet. The standard doclet adds its own set of options (see below).
The javadoc command uses Java source files (.java), package comment files, overview comment files, and unprocessed files (like images). Test and template files can be stored in the source tree but should be excluded from processing.
Each class/interface can have its own documentation comment in the source file.
Each package can have a documentation comment in package-info.java (preferred) or package.html. The comment is placed before the package declaration in package-info.java or within <body> in package.html. The javadoc command copies the comment between <body> and </body> (for package.html), processes tags, inserts the text at the bottom of the package summary page, and copies the first sentence to the top.
Example package-info.java:
/**
* Provides the classes necessary to create an
* applet and the classes an applet uses
* to communicate with its applet context.
* <p>
* The applet framework involves two entities:
* the applet and the applet context.
* An applet is an embeddable window (see the
* {@link java.awt.Panel} class) with a few extra
* methods that the applet context can use to
* initialize, start, and stop the applet.
*
* @since 1.0
* @see java.awt
*/
package java.lang.applet;
An overview comment file (e.g., overview.html) is placed anywhere; use the -overview option to specify it. The content is a big HTML comment. The first sentence becomes the summary at the top of the overview page. The processed text appears at the bottom. Only created when documenting two or more packages.
Put extra files (images, examples) in a doc-files directory inside any package directory. The javadoc command copies the entire directory to the destination. Example link in a comment: <img src="doc-files/Button.gif">.
Test files (valid compilable sources) and template files (often .java but invalid) can be stored in subdirectories with invalid names (e.g., test-files/) to avoid processing. To document test files, run javadoc with explicit file names like com/package1/test-files/*.java.
The standard doclet generates HTML files organized as follows:
classname.html).package-summary.html).overview-summary.html) when multiple packages are documented.overview-tree.html) and per package (package-tree.html).package-use.html) and per class (class-use/classname.html).deprecated-list.html).constant-values.html).serialized-form.html).index-*.html).help-doc.html).index.html (frameset).*-frame.html).package-list (for external linking).stylesheet.css.doc-files directory (copied if present).Two or three frames are generated based on the number of packages. A single package yields only the class list frame. Two or more packages add a package list frame and an overview page.
Class files are placed in a directory hierarchy mirroring the package structure. Example for java.applet with destination apidocs:
index.html (frameset)overview-summary.htmloverview-tree.htmldeprecated-list.htmlconstant-values.htmlserialized-form.htmloverview-frame.htmlallclasses-frame.htmlhelp-doc.htmlindex-all.html (or index-files/)package-liststylesheet.cssApplet.htmlAppletContext.htmlAppletStub.htmlAudioClip.htmlpackage-summary.htmlpackage-frame.htmlpackage-tree.htmlpackage-use.htmlApplet.htmlAppletContext.html-linksource used)
Each class, interface, field, constructor, and method description starts with a declaration. Modifiers shown: public, protected, private, abstract, final, static, transient, volatile. synchronized and native are not shown because they are implementation details.
A documentation comment starts with /** and ends with */. Leading asterisks on each line are ignored. The first sentence is used as the summary (copied to the member summary).
Example:
/**
* This is the typical format of a simple documentation comment
* that spans two lines.
*/
Placement: Immediately before class, interface, constructor, method, or field declarations. Do not put an import statement between the comment and the declaration.
Parts: Main description followed by a tag section (starting with the first block tag @).
Block tags (@tag) and inline tags ({@tag}) are supported. The text is written in HTML; use entities for < (<), > (>), and & (&).
Multiple-field declarations: Only one documentation comment is allowed for a statement declaring multiple fields. To have individual comments, declare each field separately.
Missing main description, @return, @param, or @throws tags are copied from the overridden method in the inheritance hierarchy. Use {@inheritDoc} to explicitly inherit a comment. Constructors, fields, and nested classes do not inherit comments.
Inheritance occurs when:
If a method lacks a comment or has {@inheritDoc}, the search order is:
Tags start with @ and are case-sensitive. They must appear at the beginning of a line (after optional asterisks). Block tags are placed in the tag section; inline tags can appear anywhere.
Custom tags are configured with the -tag option. See also How to Write Doc Comments.
@author name-text โ JDK 1.0. Adds an Author entry when -author is used. Multiple names per tag or multiple tags allowed.{@code text} โ JDK 1.5. Displays text in code font without interpreting HTML or nested tags. Equivalent to <code>{@literal}</code>.@deprecated deprecated-text โ JDK 1.0. Marks API as deprecated. Moved to italics with a bold "Deprecated" warning. Use {@link} to point to replacement.{@docRoot} โ JDK 1.3. Represents the relative path to the generated document root directory. Useful for referencing files like copyright pages.@exception class-name description โ JDK 1.0. Identical to @throws.{@inheritDoc} โ JDK 1.4. Copies documentation from the nearest inheritable class/interface. Valid in main description of a method or in @return, @param, @throws text.{@link package.class#member label} โ JDK 1.2. Inline link with visible label. Similar to @see but appears inline.{@linkplain package.class#member label} โ JDK 1.4. Like {@link} but the label is in plain text, not code font.{@literal text} โ JDK 1.5. Displays text without interpreting HTML or nested tags. No code font.@param parameter-name description โ JDK 1.0. Adds a parameter to the Parameters section. For type parameters, use angle brackets: @param <E> Type of element.@return description โ JDK 1.0. Adds a Returns section.@see reference โ JDK 1.0. Adds a "See Also" heading. Three forms:
@see "string" โ plain text reference.@see <a href="URL#value">label</a> โ HTML link.@see package.class#member label โ link to a documented element.@serial field-description | include | exclude โ JDK 1.2. Documents serializable fields. include/exclude control whether a class/package appears on the serialized form page.@serialData data-description โ JDK 1.2. Documents the types and order of data in serialized form.@serialField field-name field-type field-description โ JDK 1.2. Documents an ObjectStreamField component.@since since-text โ JDK 1.1. Adds a "Since" heading with the version when the feature was introduced.@throws class-name description โ JDK 1.2. Adds a "Throws" subheading. Same as @exception. If missing, the exception is listed without description. Copy from overridden methods only when explicitly declared.{@value package.class#field} โ JDK 1.4. Displays the value of a constant. When used without argument in a static fieldโs comment, displays its own value.@version version-text โ JDK 1.0. Adds a "Version" subheading when -version is used. Multiple tags allowed.The following tags can be used in all documentation comments: @see, @since, @deprecated, {@link}, {@linkplain}, {@docRoot}.
In overview comment files: @see, @since, @serialField, @author, @version, {@link}, {@linkplain}, {@docRoot}.
In package.html or package-info.java: @see, @since, @serial (with include/exclude), @author, @version, {@link}, {@linkplain}, {@docRoot}.
In class/interface comments: @see, @since, @deprecated, @serial (with include/exclude), @author, @version, {@link}, {@linkplain}, {@docRoot}.
Example:
/**
* A class representing a window on the screen.
* For example:
* <pre>
* Window win = new Window(parent);
* win.show();
* </pre>
*
* @author Sami Shaio
* @version 1.13, 06/08/06
* @see java.awt.BaseWindow
* @see java.awt.Button
*/
class Window extends BaseWindow { ... }
In field comments: @see, @since, @deprecated, @serial, @serialField, {@link}, {@linkplain}, {@docRoot}, {@value}.
In constructor/method comments: @see, @since, @deprecated, @param, @return (not in constructors), @throws, @exception, @serialData (only for writeObject, readObject, writeExternal, readExternal, writeReplace, readResolve), {@link}, {@linkplain}, {@inheritDoc}, {@docRoot}.
Example:
/**
* Returns the character at the specified index. An index
* ranges from <code>0</code> to <code>length() - 1</code>
*
* @param index the index of the desired character.
* @return the desired character.
* @exception StringIndexOutOfRangeException
* if the index is not in the range <code>0</code>
* to <code>length()-1</code>
* @see java.lang.Character#charValue()
*/
public char charAt(int index) { ... }
The javadoc command uses doclets to determine output. The built-in standard doclet is used unless -doclet is specified. Options are case-insensitive except arguments.
Core options (available to all doclets): -bootclasspath, -breakiterator, -classpath, -doclet, -docletpath, -encoding, -exclude, -extdirs, -help, -locale, -overview, -package, -private, -protected, -public, -quiet, -source, -sourcepath, -subpackages, -verbose.
-overview path/filename โ Specifies the file for the overview documentation. Placed on the overview page (overview-summary.html).-Xdoclint:(all|none|[-]group) โ Reports warnings for bad references, accessibility, missing comments, syntax errors, and HTML issues. Available groups: accessibility, html, missing, reference, syntax. Default: all. Disable with none.-public โ Show only public classes and members.-protected โ Show protected and public classes and members (default).-package โ Show package, protected, and public classes and members.-private โ Show all classes and members.-help โ Display online help listing all options.-doclet class โ Specifies the custom doclet class (must contain start(Root) method).-docletpath classpathlist โ Path to the doclet class and its dependencies. Separate with colon (:) or semicolon (;).-1.1 โ Removed from Javadoc 1.4. Previously generated documentation with Javadoc 1.1 appearance.-source release โ Specifies the source version accepted. Values: 1.5 (default), 1.4, 1.3.-sourcepath sourcepathlist โ Search paths for finding source files when passing package names or -subpackages. Default is classpath. Separate with colon.-classpath classpathlist โ Paths to find referenced classes. Also used to find source files if -sourcepath is omitted.-subpackages package1:package2:... โ Generates documentation for the specified packages and recursively for their subpackages.-exclude packagename1:packagename2:... โ Excludes specified packages and subpackages from -subpackages.-bootclasspath classpathlist โ Paths for bootstrap classes (Java platform classes).-extdirs dirlist โ Directories where extension classes reside.-verbose โ Provides more detailed messages during processing.-quiet โ Suppresses non-error messages and version string.-breakiterator โ Uses java.text.BreakIterator to determine the first sentence boundary (for English only; other locales already use it).-locale language_country_variant โ Specifies the locale for generated documentation (e.g., en_US). Must be placed before any doclet options.-encoding โ Specifies the encoding of source files (e.g., EUCJIS/SJIS).-Jflag โ Passes a flag directly to the JRE (e.g., -J-Xmx32m).-javafx โ Generates documentation using JavaFX extensions, adding a Property Summary section and @defaultValue tag.-d directory โ Destination directory for generated HTML files. Created if not exist. Default: current directory.-use โ Generates "Use" pages for each documented class and package.-version โ Includes @version text in the output.-author โ Includes @author text in the output.-splitindex โ Splits the index file into multiple files, one per letter.-windowtitle title โ Title for the HTML <title> tag. No HTML tags. If omitted, -doctitle is used.-doctitle title โ Title placed near the top of the overview summary file. Can contain HTML tags.-title title โ (Deprecated) Renamed to -doctitle.-header header โ Header text placed at the top of each output file (right of the navigation bar). Can contain HTML tags.-footer footer โ Footer text placed at the bottom of each output file. If omitted, the header text is copied.-top โ Text placed at the top of each output file. (Not commonly used; see -header.)-bottom text โ Text placed at the bottom of each page, below the lower navigation bar. Can contain HTML tags.-link extdocURL โ Creates links to existing Javadoc-generated documentation. Requires a package-list file at the specified URL. Multiple -link options allowed.-linkoffline extdocURL packagelistLoc โ Like -link but uses a local copy of the package-list file when the URL is not accessible.-linksource โ Generates an HTML version of each source file with line numbers and links to them from the standard documentation.-group groupheading packagepattern:packagepattern โ Separates packages on the overview page into groups. Multiple -group options allowed.-nodeprecated โ Excludes all deprecated API from the generated documentation.-nodeprecatedlist โ Prevents the generation of the deprecated-list.html file and the navigation bar link, but still generates deprecated API elsewhere.-nosince โ Omits the "Since" sections from the generated documents.-notree โ Omits class/interface hierarchy pages.-noindex โ Omits the index from the generated documents.-nohelp โ Omits the HELP link in the navigation bars.-nonavbar โ Prevents generation of the navigation bar, header, and footer.-helpfile path\filename โ Specifies an alternate help file for the HELP link.-stylesheet path/filename โ Specifies an alternate stylesheet file.-serialwarn โ Generates compile-time warnings for missing @serial tags.-charset name โ Specifies the HTML character set (e.g., ISO-8859-1).-docencoding name โ Specifies the encoding of the generated HTML files.-keywords โ Adds HTML <META> keywords for search engines.-tag tagname:Xaoptcmf:"taghead" โ Enables a custom block tag. Placement specifiers: X (disable), a (all), o (overview), p (packages), t (types), c (constructors), m (methods), f (fields). Example: -tag todo:a:"To Do:".-taglet class โ Specifies a custom taglet class for processing a tag.-tagletpath tagletpathlist โ Search paths for finding taglet class files.-docfilesubdirs โ Enables deep copying of doc-files subdirectories.-excludedocfilessubdir name1:name2 โ Excludes specified doc-files subdirectories from copying.-noqualifier all | packagename1:packagename2... โ Omits qualifying package names from class names in output.-notimestamp โ Suppresses the timestamp in the generated HTML comment.-nocomment โ Suppresses all comment text, generating only declarations.-sourcetab tablength โ Specifies the number of spaces each tab uses in the source.To shorten or simplify the command, you can use files containing arguments (except -J options). Argument files are referenced with @filename. Arguments can be space-separated or newline-separated. File names inside are relative to the current directory.
Example:
javadoc @options @packages
Options file example:
-d docs-filelist
-use
-splitindex
-windowtitle 'Java SE 7 API Specification'
-doctitle 'Java SE 7 API Specification'
-header '<b>Javaโข SE 7</b>'
-bottom 'Copyright © 1993-2011 Oracle and/or its affiliates. All rights reserved.'
-group "Core Packages" "java.*"
-overview /java/pubs/ws/1.7.0/src/share/classes/overview-core.html
-sourcepath /java/pubs/ws/1.7.0/src/share/classes
Packages file:
com.mypackage1
com.mypackage2
com.mypackage3
Release number: javadoc -J-version. The standard doclet version appears in the output stream.
Call programmatically using com.sun.tools.javadoc.Main (reentrant). See The Standard Doclet.
Document One or More Packages:
javadoc -d /home/html -sourcepath /home/src -subpackages java -exclude java.net:java.lang
Change to root and run explicit packages:
cd /home/src/
javadoc -d /home/html java.awt java.awt.event
Run from any directory on explicit packages in one tree:
javadoc -d /home/html -sourcepath /home/src java.awt java.awt.event
Document One or More Classes:
cd /home/src/java/awt
javadoc -d /home/html Button.java Canvas.java Graphics*.java
Document from root:
javadoc -d /home/html java/awt/Button.java java/applet/Applet.java
Document files from any directory:
javadoc -d /home/html /home/src/java/awt/Button.java /home/src/java/awt/Graphics*.java
Document Packages and Classes:
javadoc -d /home/html -sourcepath /home/src java.awt /home/src/java/applet/Applet.java
Command-line example (long command, better in an argument file):
javadoc -sourcepath /java/jdk/src/share/classes \
-overview /java/jdk/src/share/classes/overview.html \
-d /java/jdk/build/api \
-use \
-splitIndex \
-windowtitle 'Java Platform, Standard Edition 7 API Specification' \
-doctitle 'Java Platform, Standard Edition 7 API Specification' \
-header '<b>Javaโข SE 7</b>' \
-bottom '<font size="-1"><a href="http://bugreport.sun.com/bugreport/">Submit a bug or feature</a><br/>Copyright © 1993, 2011, Oracle and/or its affiliates. All rights reserved.<br/>Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.</font>' \
-group "Core Packages" "java.*:com.sun.java.*:org.omg.*" \
-group "Extension Packages" "javax.*" \
-J-Xmx180m \
@packages
Programmatic interface example:
import javax.tools.DocumentationTool;
import javax.tools.ToolProvider;
public class JavaAccessSample{
public static void main(String[] args){
DocumentationTool javadoc = ToolProvider.getSystemDocumentationTool();
int rc = javadoc.run( null, null, null,
"-d", "/home/html",
"-sourcepath", "home/src",
"-subpackages", "java",
"-exclude", "java.net:java.lang",
"com.example");
}
}
javadoc -sourcepath $(SRCDIR) \ /* Sets path for source files */
-overview $(SRCDIR)/overview.html \ /* Sets file for overview text */
-d /java/jdk/build/api \ /* Sets destination directory */
-use \ /* Adds "Use" files */
-splitIndex \ /* Splits index A-Z */
-windowtitle $(WINDOWTITLE) \ /* Adds a window title */
-doctitle $(DOCTITLE) \ /* Adds a doc title */
-header $(HEADER) \ /* Adds running header text */
-bottom $(BOTTOM) \ /* Adds text at bottom */
-group $(GROUPCORE) \ /* 1st subhead on overview page */
-group $(GROUPEXT) \ /* 2nd subhead on overview page */
-J-Xmx180m \ /* Sets memory to 180MB */
java.lang java.lang.reflect \ /* Sets packages to document */
java.util java.io java.net \
java.applet
WINDOWTITLE = 'Javaโข SE 7 API Specification'
DOCTITLE = 'Javaโข Platform Standard Edition 7 API Specification'
HEADER = '<b>Javaโข SE 7</font>'
BOTTOM = '<font size="-1">
<a href="http://bugreport.sun.com/bugreport/">Submit a bug or feature</a><br/>
Copyright © 1993, 2011, Oracle and/or its affiliates. All rights reserved.<br/>
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.</font>'
GROUPCORE = '"Core Packages" "java.*:com.sun.java.*:org.omg.*"'
GROUPEXT = '"Extension Packages" "javax.*"'
SRCDIR = '/java/jdk/1.7.0/src/share/classes'
-windowtitle is omitted, the document title is used for the window title.-footer is omitted, the header text is used for the footer.-classpath, -link.Error and warning messages include the file name and line number of the declaration line. Example: error: cannot read: Class1.java means the file could not be loaded.
CLASSPATH โ Environment variable providing the path to user class files. Overridden by -classpath. Example (Windows): .;C:\classes;C:\home\java\classes; (Oracle Solaris): .:/home/classes:/usr/local/java/classes.Generated by phpman v4.9.29 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-21 05:57 @2600:1f28:365:80b0:e9a9:ac35:f5fe:ea62
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format