javadoc - The Java API Documentation Generator

Generates HTML pages of API documentation from Java source files.

SYNOPSIS

javadoc options* packagename* sourcefile* @filename*

DESCRIPTION

javadoc parses the declarations and documentation comments in a set of Java source files and produces a corresponding set of HTML pages describing (by default) the public and protected classes, inner classes, interfaces, constructors, methods, and fields.

You can run javadoc on entire packages, individual classes or both. In the first case, you pass in as an argument to javadoc a series of package names. In the second case you pass in a series of source (.java) filenames. Examples are given at the end of this document.

When javadoc parses the class and member delarations, it picks up their signatures for inclusion in the output. In addition, you can add further documentation by including documentation comments in the source code.

By default, javadoc uses a standard doclet that generates HTML-formatted documentation. This doclet generates an .html file for each class and package it is documenting. In addition, it produces a class hierarchy (tree.html) for the system, a separate class hierarchy for each package, a list of deprecated API, a serialized form page, and an index of API names.

For information and workarounds for bugs in javadoc, refer to the Javadoc FAQ. For more information about how to write documentation comments, refer to How to Write Doc Comments for Javadoc.

Terminology

It is helpful to define a few terms:
generated document
The document generated by the javadoc tool from the doc comments in Java source code. The default generated document is in HTML and is created by the standard doclet.

name
A name in the Java Language, namely the name of a package, class, interface, field, constructor or method. A name can be fully-qualified, such as java.lang.String.equals(java.lang.Object), or partially-qualified, such as equals(Object).

documented classes
The classes and interfaces for which full documentation is generated during a javadoc run. To be documented, the source files must be available, and either their source filenames or package names must be passed into the javadoc command. We also refer to these as the classes included in the javadoc run, or the included classes.

referenced classes
The classes and interfaces that are explicitly referred to in the definition of the documented classes and interfaces. Examples of references include return type, parameter type, cast type, extended class, implemented interface, imported classes, and so forth. Classes referred to in doc comments (such as @see tags) do not qualify as referenced classes. When Javadoc is run, it loads into memory all of the referenced classes in javadoc's bootclasspath and classpath. (Javadoc prints a "Class not found" warning for referenced classes not found.) Javadoc can derive enough information from the the .class files to determine their existence and the fully-qualified names of its members. That plus their documentation URL allows their docs to be linked to.

external referenced classes
The referenced classes whose documentation is not being generated during a javadoc run. In other words, these classes are external to that javadoc run. Links for names in the documentation to those classes are said to be external references or external links. For example, if you run javadoc on only the java.awt package, then then any class in java.lang, such as Object, is an external referenced class.

Javadoc Doclets

You can customize the content and format of javadoc's output by using doclets. Information about doclets and their use is at the following locations: When a custom doclet is not specified with the -doclet command line option, javadoc will use the default standard doclet that produces HTML-formatted API documentation. The javadoc tool has several command line options that are available regardless of which doclet is being used. The standard doclet adds a supplementary set of command line options. Both sets of options are described below in the options section.

Commenting the Source Code

You can include documentation comments in the source code, ahead of declarations for any entity (classes, interfaces, methods, constructors, or fields). A doc comment consists of the characters between the characters /** that begin the comment and the characters */ that end it. The text is divided into one or more lines. When javadoc parses a doc comment, leading * characters on each line are discarded; blanks and tabs preceding the initial * characters are also discarded. These comments may include HTML tags. Here is a doc comment:

/**
 * This is a <b>doc</b> comment.
 */

The first sentence of each doc comment should be a summary sentence, containing a concise but complete description of the declared entity. This sentence ends at the first period that is followed by a blank, tab, or line terminator, or at the first tag (as defined below). javadoc copies this first sentence to the member summary at the top of the .html file.

Documentation comments are only recognized when placed immediately before class, interface, constructor, method, or field declarations.

When you embed HTML tags within a doc comment, you should not use heading tags such as <h1> and <h2>, because javadoc creates an entire structured document and these structural tags interfere with the formatting of the generated document.

For the specification on documentation comments, see Chapter 18, Documentation Comments, in the Java Language Specification, by James Gosling, Bill Joy, and Guy Steele.

Tagged Paragraphs

javadoc parses special tags when they are embedded within a Java doc comment. These doc tags enable you to autogenerate a complete, well-formatted API from your source code. The tags start with an "at" sign (@).

Tags must start at the beginning of a line (after any leading spaces and an optional asterisk). By convention, keep tags with the same name together. For example, put all @see tags together.

For information about proposed tags, see Proposed Tags.

@author  name-text
Adds an "Author" entry with the specified name-text to the generated docs when the -author option is used. The text has no special internal structure. A doc comment may contain multiple @author tags.

@deprecated  deprecated-text
Adds a comment indicating that this API should no longer be used (even though it may continue to work). The convention is to describe the API that serves as a replacement. For example:
    @deprecated  Replaced by setBounds(int, int, int, int).
If the member is obsolete and there is no replacement, the argument to @deprecated should be "No replacement".

For more about this tag, see The @deprecated tag.

@exception  class-name  description
The @exception tag is a synonym for @throws.

{@link  name  label}
Inserts an in-line link that points to the specified name. This tag accepts exactly the same syntax for name and label as the @see tag, described immediately above, but generates an in-line link rather than placing the link in the "See Also" section. This tag begins and ends with curly braces to separate it from the rest of the in-line text.

For example, here is a comment that refers to the getComponentAt(int, int) method:

Use the {@link getComponentAt(int, int) getComponentAt} method.
From this, the standard doclet would generate the following HTML:
Use the <a href="Component#getComponentAt(int, int)">getComponentAt</a> method.
Which appears on the web page as:
Use the getComponentAt method.
@param  parameter-name description
Adds a parameter to the "Parameters" section. The description may be continued on the next line.

@return  description
Adds a "Returns" section with the description text. This text should describe the return type and permissible range of values.

@see  reference
Adds a "See Also" heading with a link or text entry that points to reference. A doc comment may contain any number of @see tags, which are all grouped under the same heading. The @see tag has three variations:

@see  package.class#member  label
Adds a link, with visible text label, that points to the documentation for the specified name in the Java Language. The label is optional; if omitted, the name appears instead. Use the label when you want the visible text to be abbreviated or different from the name. This form is described in greater detail below, along with examples.

@see <a href="URL#value">label</a>
Adds a link as defined by URL#value. The URL#value is a relative or absolute URL. Javadoc distinguishes this from the previous case by looking for a less-than symbol (<) as the first character. An example is shown below.

@see "string"
Adds a text entry for string. No link is generated. The string is a book or other reference to information not available by URL. Javadoc distinguishes this from the previous cases by looking for a double-quote (") as the first character. An example is shown below.

The second and third forms above are straightforward; the first forms requires further elaboration. The two arguments to the first form are as follows:

  • package.class#member is any valid name in the Java Language -- the name of a package, class, interface, constructor, method or field -- except that the hash character replaces the dot ahead of the member name. If this name belongs to the documented classes, Javadoc will automatically create a link to it. To create links to external referenced classes, use the -link option. Use either of the other two @see forms for referring to documentation of a name that does not belong to a referenced class.

    This name can be either fully-qualified or partially-qualified. If partially-qualified, javadoc uses the normal javac compiler search order to fully-qualify it, further described below in Search order for @see. The name can contain whitespace within parentheses, such as between method argument types.

    Of course the advantage to providing shorter, partially-qualified names is that it is less to type and easier to read in the source code. The follow are the different forms of the name, where Class can be a class or interface, Type can be a class, interface, array, or primitive, and method can be a method or constructor.

    As stated in Note 1 below, the first four forms (that begin with #) work only if the name is in the current class or interface, one of its superclasses or superinterfaces, or one of its enclosing classes or interfaces.

    Partially- and Fully-Qualified Names for @see
    @see  #field
    @see  #method
    @see  #method(Type, Type,...)
    @see  #method(Type argname, Type argname,...)
    @see  Class
    @see  Class#field
    @see  Class#method
    @see  Class#method(Type, Type,...)
    @see  Class#method(Type argname, Type argname,...)
    @see  package.Class
    @see  package.Class#field
    @see  package.Class#method
    @see  package.Class#method(Type, Type,...)
    @see  package.Class#method(Type argname, Type argname,...)
    @see  package
    [Note 1]
    [Note 1]
    [Note 1]
    [Note 1]
    [Note 2]

    Note 1 - The forms with no class or package will search only through the current class's hierarchy (search steps 1-3), and will not search the rest of the current package or other packages (search steps 4-5).

    Note 2 - Inner classes must be specified as outer.inner, not simply inner, for all forms.

    You can select one of several overloaded methods or constructors by fully-qualifying it -- that is, including its parenthesized list of argument types.

    Notice that the hash character (#), rather than a dot (.) separates a member from its class. This enables Javadoc to resolve ambiguities, since the dot also separates classes, inner classes, packages, and subpackages. The hash character is absolutely necessary in the first five forms above, when it is the first character. However, in other cases, Javadoc is generally forgiving and will allow a dot if it does not produce an ambiguity, though it will print a warning. Notice that you can omit the parentheses from a constructor or method if there is no ambiguity (that is, if there is no field by that name).

    In general, if you provide no label, whatever you type as an argument to the @see tag will appear as the label. However, if the method is not in the current class, Javadoc will prepend the class name.

  • label is optional text that is visible as the link's label; if omitted, the name will appear as the link's label. The label can contain whitespace.

Detailed Example of @see
Starting with a simple example, here is the @see tag in the source code:

 /**
  * @see String#equals(Object) 
  */
The standard doclet produces HTML something like this:
<dl>
<dt><b>See Also:</b>
<dd><a href="../../java/lang/String#equals(java.lang.Object)">String.equals(java.lang.Object)</a>
</dl>
Which looks something like this in a browser:

See Also:
String.equals(Object)
More Examples of @see
The second example below includes a label.
@see java.lang.String                   // See also: java.lang.String
@see java.lang.String The String class  // See also: The String class
@see String                             // See also: String
@see String#equals()                    // See also: String.equals()
@see String#equals                      // See also: String.equals()     [Note 1] 
@see java.lang.Object#wait(int)         // See also: java.lang.Object.wait(int)
@see Character#MAX_RADIX                // See also: Character.MAX_RADIX
@see <a href="spec.html">Java Spec</a>  // See also: Java Spec
@see "The Java Programming Language"    // See also: The Java Programming Language
Note 1 - Because the parentheses following equals are missing, Javadoc first looks for a field named "equals" in the String class before looking for a method by that name.

Search Order for @see - Javadoc searches for the specified API in the same order as the Java compiler (except Javadoc will not detect certain namespace ambiguities, since it assumes the source code is free of these errors). This search order is formally defined in Chapter 6, "Names" of the Java Language Specification, modified by the Inner Classes Specification. Thus, you can specify a name that is fully-qualified or partially-qualified. When specifying a name that is not fully-qualified, Javadoc searches for that name through all related and imported classes and packages. In particular, it searches in this order:

  1. the current class or interface
  2. any enclosing classes and interfaces, searching closest first
  3. any superclasses and superinterfaces, searching closest first
  4. the current package
  5. any imported packages, classes and interfaces, searching in the order of the import statement

Javadoc continues to search recursively through steps 1-3 for each class it encounters until it finds a match. That is, after it searches through the current class and its enclosing class E, it will search through E's superclasses before E's enclosing classes. In steps 4 and 5, Javadoc does not search classes or interfaces within a package in any specified order (that order depends on the particular compiler). In step 5, Javadoc will look in java.lang, since that is automatically imported by all programs.

Javadoc won't look in other packages even if their documentation is being generated in the same run. Notice that Javadoc won't automatically look in "superpackages" (unless the class imports it). Nor will it necessarily look in subclasses.

@since  since-text
Adds a "Since" heading with the specified since-text to the generated documentation. The text has no special internal structure. This tag means that this change or feature has existed since the software release specified by the since-text. For example:
    @since JDK1.1

@serial  field-description
Used in the doc comment for a default serializable field.

An optional field-description augments the doc comment for the field. The combined description must explain the meaning of the field and list the acceptable values. If needed, the description can span multiple lines.

The @since tag should be added to each serializable field that has been added since the initial version of a Serializable class.

For more information about how to use these tags, along with an example, see "Documenting Serializable Fields and Data for a Class," Section 1.6 of the Java Object Serialization Specification.

@serialField  field-name  field-type  field-description
Documents an ObjectStreamField component of a Serializable class' serialPersistentFields member. One @serialField tag should be used for each ObjectStreamField component.

@serialData  data-description
A data-description documents the sequences and types of data, specifically the optional data written by the writeObject method and all data written by the Externalizable.writeExternal method.

The @serialData tag can be used in the doc comment for the writeObject, readObject, writeExternal, and readExternal methods.

@throws  class-name  description
The @throws and @exception tags are synonyms. Adds a "Throws" subheading to the generated documentation, with the class-name and description text. The class-name is the name of the exception that may be thrown by the method. If this class is not fully-specified, Javadoc uses the search order to look up this class.

@version  version-text
Adds a "Version" subheading with the specified version-text to the generated docs when the -version option is used. The text has no special internal structure. A doc comment may contain at most one @version tag. Version normally refers to the version of the software (such as the JDK) that contains this class or member.

Where Tags Can Be Used

The following sections describe where the tags can be used. Note that these four tags can be used in all doc comments: @see, @link, @since, @deprecated.


Package Documentation Tags

Package tags are tags that can appear in the documentation comment for a package (which resides in the package.html file).

Package Tags
@see
{@link}
@since
@deprecated

Class and Interface Documentation Tags

The following are tags that can appear in the documentation comment for a class or interface.

Class/Interface Tags
@see
{@link}
@since
@deprecated
@author
@version

An example of a class comment:

/**
 * A class representing a window on the screen.
 * For example:
 * <pre>
 *    Window win = new Window(parent);
 *    win.show();
 * </pre>
 *
 * @author  Sami Shaio
 * @version %I%, %G%
 * @see     java.awt.BaseWindow
 * @see     java.awt.Button
 */
class Window extends BaseWindow {
   ...
}

Field Documentation Tags

The following are the tags that can appear in the documentation comment for a field.

Field Tags
@see
{@link}
@since
@deprecated
@serial
@serialField

An example of a field comment:

    /**
     * The X-coordinate of the component.
     *
     * @see #getLocation()
     */
    int x = 1263732;

Constructor and Method Documentation Tags

The following are the tags that can appear in the documentation comment for a constructor or method.

Method/Constructor Tags
@see
{@link}
@since
@deprecated
@param
@return
@throws (@exception)
@serialData

An example of a method doc comment:

    /**
     * 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) {
       ...
    }

OPTIONS

The javadoc tool uses doclets to determine its output. Javadoc uses the default standard doclet unless a custom doclet is specified with the -doclet option. Javadoc provides a set of command-line options that can be used with any doclet. These options are described below under the sub-heading Javadoc Options. The standard doclet provides an additional set of command-line options that are described below under the sub-heading Options Provided by the Standard Doclet.

All option names are case-insensitive, though their arguments can be case-sensitive.

Argument File

You can specify a file containing additional arguments by including an argument beginning with the character '@', in the form @filename. This file can have one or more arguments per line. The arguments in this file are inserted into the command line at the position of the @filename argument. This enables you to create javadoc commands of any length. (Windows has a command line limitation of about 1000 characters.) For example, here are three typical ways you might use the argument file: For all arguments, for only the options, or for only the packages/classes.
     javadoc @args

     javadoc @options java.awt java.awt.event

     javadoc -d C:\home\html @packages

Javadoc Options

-overview  path
Specifies that javadoc should retrieve overview documentation from the file specified by path. javadoc will take whatever appears between the body HTML tags (<body>, </body>) in the overview file, interpret it as HTML, and place it on the package index file (packages.html) beneath the alphabetical list of package links.

-public
Shows only public classes and members.

-protected
Shows only protected and public classes and members. This is the default.

-package
Shows only package, protected, and public classes and members.

-private
Shows all classes and members.

-help
Displays the online help, which lists these javadoc and doclet command line options.

-doclet  class
Specifies the class file that starts the doclet used in generating the documentation. This doclet defines the content and formats the output. If the -doclet option is not used, javadoc 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  pathlist
Specifies the path to the doclet class file that is specified with the -doclet option. This option is not necessary if the doclet is already in the search path.

-1.1
Generates the documentation with the appearance and functionality of documentation generated by javadoc 1.1. That is, the pages have a gray background, use images for headers, have bulleted lists instead of tables, use a flat destination directory structure, do not contain inherited API, do not use HTML frames, and do not support inner classes. Is you want this appearance, this has the advantage over javadoc 1.1 of having some bugs fixed.

-sourcepath  pathlist
Specifies the search path for source files (.java). See -classpath (below) for more details. Set sourcepath to the root directory of the source tree for the package name you are documenting. For example, suppose you want to document a package called java.lang whose source files are located at:
C:\myapp\src\java\lang\*.java
In this case you would specify the sourcepath to be the directory that contains java/lang, and then supply the package name java.lang:
javadoc -sourcepath C:\myapp\src\share java.lang
-classpath  pathlist
Specifies the paths where user classes reside. User classes are classes other than the Java core classes and extensions classes (classes using the extension mechanism). This classpath is part of the search path Javadoc uses to find source (.java) and class (.class or .jar) files. When looking for a class, Javadoc will look in this order and load the first class by that name that it finds:

  • bootclasspath for .class or .jar files
  • extdirs for .class or .jar files
  • classpath for .java or .class/.jar files, which ever is the most recent

This is described further in Configuration of JDK Software.

For example, if you create your own classes, use -classpath to specify where they are located.

Note that if -sourcepath is not specified, -classpath specifies the path javadoc uses to look up the .java files. If -sourcepath is specified, Javadoc uses it rather than -classpath to find .java files.

The pathlist can contain multiple paths by separating them with a colon. The following example sets two paths: current directory (.) and /home/opus/myclasses:

javadoc -classpath .:/home/opus/myclasses myPackage.MyClass

-bootclasspath  pathlist
Specifies the paths where the boot classes reside. These are nominally the Java core classes. The bootclasspath is part of the search path Javadoc will use to look up source and class files. See -classpath (above) for more details. Separate directories in dirlist with colons (:).

-extdirs  dirlist
Specifies the directories where extension classes reside. These are any classes that use the Java Extension mechanism. The extdirs is part of the search path Javadoc will use to look up source and class files. See -classpath (above) for more details. Separate directories in dirlist with colons (:).
-verbose
Provides more detailed messages while javadoc is running. Without the verbose option, messages appear for loading the source files, generating the documentation (one message per source file), and sorting. The verbose option causes the printing of additional messages specifying the number of milliseconds to parse each java source file.

-locale  language_country_variant
Specifies the locale that javadoc uses when generating 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 javadoc to choose the resource files of that locale for messages (strings in the navigation bar, headings for lists and tables, help file contents, comments in stylesheet.css, and so forth). It also specifies the sorting order for lists sorted alphabetically, and the sentence separator to determine the end of the first sentence. It does not determine the locale of the doc comment text specified in the source files of the documented classes.

-encoding  name
Specifies the source file encoding name, such as EUCJIS/SJIS. If this option is not specified, the platform default converter is used.

-Jflag
Passes flag directly to the runtime system java that runs javadoc. Notice there must be no space between the J and the flag. For example, if you need to ensure that the system sets aside 32 megabytes of memory to hold the generated documentation, then you would use this flag as follows:
javadoc -J-Xmx32m -J-Xms32m <classes> ...

Options Provided by the Standard Doclet

-d  directory
Specifies the destination directory where javadoc saves the generated HTML files. (The "d" means "destination.") Omitting this option causes the files to be saved to the current directory. The value directory can be absolute or relative to the current working directory. For example, the following generates the documentation for the java.lang package and saves the results in the C:\opus\doc\ directory:
javadoc -d C:\opus\doc java.lang

-use
Includes one "Uses" page for each documented class and package. The page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given the class or package of interest is A, this includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A.

You can access this page by first going to the class or package, then clicking on the "Use" link in the navigation bar.

-version
Includes the @version text in the generated docs. This text is omitted by default.

-author
Includes the @author text in the generated docs.

-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 characters.

-windowtitle  title
This option does not exist in Beta4, but will be in the final release
Specifies the title to be placed in the HTML <title> tag. This 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, as the browser will not properly interpret them. Any internal quotation marks within title may have to be escaped. If -windowtitle is omitted, Javadoc uses the value of -doctitle for this option.

-doctitle  title
This option is known as -title in Beta4
Specifies the title to be placed near the top of the overview summary file. The title will be placed as a centered, level-one heading directly beneath the upper navigation bar. The title may contain html tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within title may have to be escaped.

-title  title
This option will be renamed to -doctitle in the final release
This option is being renamed to make it clear that it defines the document title -- its text can include HTML. The option -windowtitle can be specified without HTML. See -doctitle for more information.

-header  header
Specifies the header text to be placed at the top of each output file. The header will be placed to the right of the upper navigation bar. header may contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within header may have to be escaped.

-footer  footer
Specifies the footer text to be placed at the bottom of each output file. The footer will be placed to the right of the lower navigation bar. footer may contain html tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within footer may have to be escaped.

-bottom  text
Specifies the text to be placed at the bottom of each output file. The text will be placed at the bottom of the page, below the lower navigation bar. The text may contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within text may have to be escaped.

-link  docURL
This option is not in 1.2Beta4, but will be in the final 1.2 version
Create links to existing javadoc-generated documentation for classes not being documented in the current javadoc run. This allows, for instance, third party documentation to link to java.* documentation on http://java.sun.com. Another use is to execute javadoc on one set of packages, then run it again on another set of packages, creating cross-links between both sets. Still another use is to execute javadoc on one set of packages, then run it again on a subset of those packages and maintain links to the entire set.

Specify -link with a URL to the external documentation:

  • docURL is the URL for the javadoc-generated external documentation you want to link to. This location can be a relative or absolute URL.

For these links to go to valid pages, you must know where those HTML pages are located, and specify that location with docURL.

You can supply multiple -link options to link to any number of external generated documents.

Without this option, javadoc does not create links to documentation for external references, because Javadoc does not know if (or where) that documentation exists.

Use the -link option as follows:

  • Omit the -link option for javadoc to create links only to API within the documentation it is generating in the current run.

  • Include the -link option for javadoc to also create links to documentation at location docURL for external referenced classes.

Note that this option requires access to the URL when you run javadoc. Thus, if the URL is on the World Wide Web, you must have a web connection when generating the documentation. If you do not, you can use -linkoffline instead.

This option requires that a file named package-list, which is generated by Javadoc, exist at the URL you specify with -link. Javadoc uses this file to determine which packages are documented at that location. This file is further described below.

Specify a different link option for each external document to link to:

javadoc -link docURL1 -link docURL2 ... -link docURLn mypackage

where docURL1docURL2,  ... docURLn point respectively to the roots of external documents, each of which contains a file named package-list. The file is a simple text file that lists the names of packages documented at that location. For java.*, this list would be:

  java.applet  
  java.awt
  java.awt.color
  etc.
The package list for the Java Platform 1.2 API is located at http://java.sun.com/products/jdk/1.2/docs/api/package-list.

Note that this option requires that javadoc have a URL connection to the file when javadoc is running, in order to access the package-list file.

For example:

javadoc -link http://java.sun.com/products/jdk/1.2/docs/api
When javadoc is run without the -link option, as it generates documentation, when it encounters a name that belongs to an external referenced class, it prints the name with no link. However, when the -link option is used, Javadoc searches the package-list file at the specified docURL location for the package of that name. If it finds the package name, it prefixes the name with that URL. (If the URL is relative and the -d destination directory option is relative, Javadoc prepends the relative path of the destination directory to the URL so that links will work from the destination directory.)

In order for there to be no broken links, all of the documentation for the external references must exist at the specified URLs. Javadoc will not check that these pages exist -- only that the package-list exists. Note that Javadoc cannot link to a class that is not in the classpath of javadoc. Conversely, to link to a class, move it into the classpath, or modify the classpath to include it.

The package-list file is created but is empty if the argument to javadoc is source files rather than packages.

Note that "bootstrapping" may be required when cross-linking two or more documents that have not previously been generated. In other words, if package-list does not exist for either document, when you run javadoc on the first document, the package-list will not yet exist for the second document. Therefore, to create the external links, you must re-generate the first document after generating the second document.

In this case, the purpose of first generating a document is to create its package-list (or you can create it by hand it if you're certain of the package names). Then generate the second document with its external links. Javadoc prints a warning if a needed external package-list file does not exist.

The other use for -link option is when you hafe previously run javadoc on a source tree and now, in a separate run, you want to update just a portion of the tree. Simply set -link and -d to the same relative path.

 javadoc -d html -link html mypackage
Background information: In general, when javadoc runs, it has the potential to generate links for names that appear throughout its generated pages: in signatures, @see tags, {@link} tags, summaries, hierarchies, the overview, and the index. Some of these links will go to pages generated in the current run, while other links will potentially go to pages not generated in the current run.

-linkoffline  docURL  packagelistURL
This option is not in 1.2Beta4, but will be in the final 1.2 version
This option creates links to documentation for names of external reference classes where:

  • docURL is the URL for the javadoc-generated external documentation you want to link to. This location can be a relative or absolute URL.

  • packagelistURL is the URL for the package-list file for that documentation. You can create this file yourself by hand if you need to.

This option is a variation on -link. You can use -linkoffline if the packages-list file does not exist at the docURL location at the time you run javadoc. If you know what package names your document will link to, and where that document will reside, it lets you generate documentation with those external links prior to when the package-list file actually exists at that location. This enables you to use your own copy of package-list to generate the documentation with the proper links.

This is useful when you need to generate documentation that links to new external documentation whose package names you know, but is not yet published. This enables two companies to release their documentation simultaneously. It also allows you to generate documentation that links to external documentation that has no package-list file (perhaps because it was generated with Javadoc 1.2 Beta3).

Note that this option does not require access to the documentation URL when you run javadoc. Thus, if the URL is on the World Wide Web, you do not need a web connection when generating the documentation.

As shown below, to use this option, specify docURL1, the location of the javadoc-generated documentation for external referenced classes, and packagelistURL1, the location of its package-list file. If they have the same location, you can just use -link instead. Include -linkoffline once for each generated document you want to refer to:

javadoc -linkoffline docURL1 packagelistURL1 -linkoffline docURL2 packagelistURL2

-group  groupheading  packagepattern:packagepattern:...
This option is not in 1.2Beta4, but will be in the final 1.2 version
Separates packages on the overview page into whatever groups you specify, one group per table. You specify each group with a different -group option. The groups appear on the page in the order specified on the command line; packages are alphabetized within a group. For a given -group option, the packages matching the list of packagepattern expressions appear in a table with the heading groupheading.

  • groupheading can be any text, and can include white space. This text is placed in the table heading for the group.

  • packagepattern can be any package name, or can be the start of any package name followed by an asterisk (*). The asterisk is a wildcard meaning "match any characters". This is the only wildcard allowed. Multiple patterns can be included in a group by separating them with colons (:).
NOTE: If using an asterisk in a pattern or pattern list, the pattern list must be inside quotes, such as "java.lang*:java.util"

If you do not supply any -group option, all packages are placed in one group with the heading "Packages". If the all groups do not include all documented packages, any leftover packages appear in a separate group with the heading "Other Packages".

For example, the following option separates the four documented packages into core, extension and other packages. Notice the trailing "dot" does not appear in "java.lang*" -- including the dot, such as "java.lang.*" would omit the java.lang package.

    javadoc -group "Core Packages" "java.lang*:java.util"
            -group "Extension Packages" "javax.*"
            java.lang java.lang.reflect java.util javax.servlet java.new
This results in the groupings:
Core Packages
java.lang
java.lang.reflect
java.util
Extension Packages
javax.servlet
Other Packages
java.new

-nodeprecated
Prevents the generation of any deprecated API at all in the documentation. This does what -nodeprecatedlist does, plus it does not generate any deprecated API throughout the rest of the documentation. This is useful when writing code and you don't want to be distracted by the deprecated code.

-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. (However, javadoc continues to generate the deprecated API throughout the rest of the document.) This is useful if your source code contains no deprecated API, and you want to make the navigation bar cleaner.

-notree
Omits the class/interface hierarchy from the generated docs. The hierarchy is produced by default.

-noindex
Omits the index from the generated docs. The index is produced by default.

-nohelp
Omits the HELP link in the navigation bars at the top and bottom of each page of output.

-nonavbar
Prevents the generation of the navigation bar, header and footer, otherwise found at the top and bottom of the generated pages. Has no affect on the "bottom" option. The -nonavbar option is useful when you are interested only in the content and have no need for navigation, such as if processing or converting the files for use in a non-HTML system.

-helpfile  path
Specifies the path of an alternate help file that the HELP link in the top and bottom navigation bars link to. Without this option, Javadoc automatically creates a help file help-doc.html that is hard-coded in Javadoc. This option enables you to override this default.

-stylesheetfile  path
Specifies the path of an alternate HTML stylesheet file. Without this option, Javadoc automatically creates a stylesheet file stylesheet.css that is internally hard-coded. is hard-coded in Javadoc. This option enables you to override this default.

-docencoding  name
Specifies the encoding of the output HTML files.

JAVADOC OUTPUT

HTML Frames

Javadoc will generate either two or three HTML frames, as shown in the figure below. When you pass into javadoc source files (*.java) or a single package name, it will create only one frame (C) in the left-hand column -- the list of classes. When you pass into javadoc two or more package names, it creates a third frame (P) listing all packages, as well as an overview page (Detail). You can bypass frames by clicking on the "No Frames" link or entering at overview-summary.html.

              ------------                  ------------
              |C| Detail |                  |P| Detail |
              | |        |                  | |        |
              | |        |                  |-|        |
              | |        |                  |C|        |
              | |        |                  | |        |
              | |        |                  | |        |
              ------------                  ------------
             javadoc *.java           javadoc java.lang java.awt

SIMPLE EXAMPLES

You can run javadoc on entire packages or individual classes. Each package name has a corresponding directory name. In the following examples, the source files are located at C:\home\src\java\awt\*java. The destination directory is C:\home\html.

Documenting One or More Packages

To document a package, the source files (*.java) for that package must be located in a directory having the same name as the package. If a package name is made up of several identifiers (separated by dots), each identifier represents a different directory. Thus, all java.awt classes must reside in a directory named java\awt\. You can run javadoc either of the following two ways -- by changing directories (with cd) or by using sourcepath option:

Both cases generate HTML-formatted documentation for the public and protected classes and interfaces in packages java.awt and java.awt.event and save the HTML files in the specified destination directory (C:\home\html). Because two or more packages are being generated, the document has three frames -- for the list of packages, the list of classes, and the main page.

Documenting One or More Classes

To document one or more .java files, the source files do not have to be in any particular directories. You can run javadoc either of the following two ways -- by changing directories (with cd) or by fully-specifying the path to the .java files:

Documenting Packages and Classes

You can document entire packages and individual classes at the same time. Here's an example that mixes the previous two examples. You can use sourcepath for the path to the packages but not for the path to the individual classes.
  C:> javadoc -d C:\home\html -sourcepath C:\home\src java.awt C:\home\src\Test.java
This example generates HTML-formatted documentation for the package java.awt and class Test. (Javadoc determines the package name for Test from the package declaration, if any, in the Test.java source file.)

REAL WORLD EXAMPLE

Javadoc has many useful options, some of which are more commonly used than others. Here is effectively the command we use to run javadoc on the Java Core API, using makefile variables (except not all packages to be documented are listed).
javadoc -sourcepath /jdk/src/share/classes \   /* Path for source files          */
        -d /jdk/build/api                  \   /* 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)                \   /* Core heading for overview page */
        -group $(GROUPEXT)                 \   /* Ext heading for overview page  */
        -overview overview-core.html       \   /* For overview text              */
        -J-mx180m                          \   /* For 180MB memory               */
        java.lang java.lang.reflect        \   /* Packages to document           */
        java.util java.io java.net         \
        java.applet
        
DOCTITLE = 'Java<sup><font size="-2">TM</font></sup> Platform 1.2 Final API Specification'
WINDOWTITLE = 'Java Platform 1.2 Final API Specification'
HEADER = '<b>Java Platform 1.2</b><br><font size="-1">Final</font>'
BOTTOM = '<font size="-1"><a href="http://java.sun.com/cgi-bin/bugreport.cgi">Submit
    a bug or feature</a><br><br>Java is a trademark or registered trademark 
    of Sun Microsystems, Inc. in the US and other countries.<br>Copyright 1993-1998    
    Sun Microsystems, Inc. 901 San Antonio Road,<br>Palo Alto, California, 94303, U.S.A.  
    All Rights Reserved.</font>'
GROUPCORE = '"Core Packages" "java.*:com.sun.java.*:org.omg.*"
GROUPEXT  = '"Extension Packages" "javax.*"'

If you omit the -windowtitle option, javadoc copies the doc title to the window title. The -windowtitle option would not be needed except for the fact that the doc title contains HTML tags,

If you omit the -footer option, as done here, javadoc copies the header text to the footer.

Other important options are -classpath and -link.

ENVIRONMENT

CLASSPATH
Provides the path which javadoc uses to find user class files. Separate directories with a semi-colon, for example,
.;C:\classes;C:\home\java\classes

SEE ALSO

javac, java, jdb, javah, javap, Configuration of JDK Software, Javadoc Home Page