javadoc

 


 javadoc(1)                                             javadoc(1)
 
 
 

NAME

javadoc - Java API documentation generator

SYNOPSIS

javadoc [ options ] [ packagenames ] [ sourcefiles ] [ @files ] PARAMETERS Parameters can be in any order. options Command-line options, as specified in this document. To see a typical use of javadoc options, see Real World Example. packagenames A series of names of packages, separated by spaces, such as java.lang java.lang.reflect java.awt. You must separately specify each package you want to document. javadoc uses -sourcepath to look for these package names. javadoc does not recursively tra­ verse subpackages. Wildcards such as asterisks (*) are not allowed. See EXAM­ PLES, Documenting One or More Packages. sourcefiles A series of source file names, separated by spaces, each of which can include paths and wildcards such as asterisk (*). The path that precedes the source file name deter­ mines where javadoc will look for it. (javadoc does not use -sourcepath to look for these source file names.) For example, passing in Button.java is identical to ./Button.java. An example source file name with a full path is /home/src/java/awt/Graphics*.java. See EXAMPLES, Documenting One or More Classes. You can also mix packagenames and source­ files, as in EXAMPLES, Documenting Both Packages and Classes. @files One or more files that contain packagenames and sourcefiles in any order.

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, construc­ tors, methods, and fields. You can run javadoc on entire packages, individual source files, 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) file names. See EXAMPLES at the end of this document. As implemented, javadoc requires and relies on the java compiler to do its job. javadoc calls part of javac to compile the declarations, ignoring the member implementa­ tion. It builds a rich internal representation of the classes, including the class hierarchy, and "use" rela­ tionships, then generates the HTML from that. javadoc also picks up user-supplied documentation from documenta­ tion comments in the source code. In fact, javadoc will run on .java source files that are pure stub files with no method bodies. This means you can write documentation comments and run javadoc in the earli­ est stages of design while creating the API, before writ­ ing the implementation. Relying on the compiler ensures that the HTML output cor­ responds exactly with the actual implementation, which may rely on implicit, rather than explicit, source code. For example, javadoc will document default constructors (sec­ tion 8.6.7 of Java Language Specification) that are pre­ sent in the .class files but not in the source code. When javadoc builds its internal structure for the docu­ mentation, it loads all referenced classes. Because of this, javadoc must be able to find all referenced classes, whether bootstrap classes, extensions, or user classes. For more about this, see How Classes Are Found. Generally speaking, classes you create must either be loaded as an extension or in the class path of javadoc. javadoc Doclets You can customize the content and format of the output of javadoc by using doclets. javadoc has a default "built- in" doclet, called the standard doclet, that generates HTML-formatted API documentation. You can modify or sub­ class the standard doclet, or write your own doclet to generate HTML, XML, MIF, RTF or whatever output format you prefer. Information about doclets and their use is at the following locations: · javadoc Doclets · The -doclet command-line option When a custom doclet is not specified with the -doclet command line option, javadoc uses the default standard doclet. 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. Terminology A few terms have specific meanings within the context of javadoc: 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, inter­ face, 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 pack­ age 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 defini­ tion (implementation) of the docu­ mented classes and interfaces. Exam­ ples of references include return type, parameter type, cast type, extended class, implemented interface, imported classes, classes used in method bodies, and so forth. Classes referred to in doc comments (such as @see tags) do not qualify as refer­ enced classes. When javadoc is run, it loads into memory all of the refer­ enced classes in the bootclasspath and classpath of javadoc. (javadoc prints a "Class not found" warning for refer­ enced classes not found.) javadoc can derive enough information from the .class files to determine their exis­ tence and the fully qualified names of their members. external referenced classes The referenced classes with documenta­ tion not being generated during a javadoc run. In other words, these classes are external to that javadoc run. Links for names in the documen­ tation 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 any class in java.lang, such as Object, is an external referenced class. Exter­ nal referenced classes can be linked to using the -link option. Source Files javadoc generates output originating from four different types of "source" files: Java language source files for classes (.java), package comment files, overview comment files, and miscellaneous unprocessed files. Class Source Code Files Each class or interface and its members can have their own documentation comment, contained in a .java file. For more details about these doc commments, see Documentation Comments below. Package Comment Files Each package can have its own documentation comment, con­ tained in its own "source" file, that javadoc will merge into the package summary page that it generates. You typ­ ically include in this comment any documentation that applies to the entire package. To create a package comment file, you must name it package.html and place it in the package directory in the source tree along with the .java files. javadoc automati­ cally looks for this filename in this location. Notice that the filename is identical for all packages. The content of the package comment file is one big docu­ mentation comment, written in HTML, like all other com­ ments, with one exception, namely, the documentation com­ ment should not include the comment separators /** and */ or leading asterisks. When writing the comment, you should make the first sentence a summary about the pack­ age, and not put a title or any other text between <body> and the first sentence. You can include package tags; as with any documentation comment, all tags except {@link} must appear after the description. If you add a @see tag in a package comment file, it must have a fully qualified name. When javadoc runs, it automatically looks for this file; if found, javadoc does the following: · Copies all content between <body> and </body> tags for processing. · Processes any package tags that are present. · Inserts the processed text at the bottom of the package summary page it generates, as shown in Package Summary. · Copies the first sentence of the package comment to the top of the package summary page. It also adds the pack­ age name and this first sentence to the list of packages on the overview page, as shown in Overview Summary. The end-of-sentence is determined by the same rules used for the end of the first sentence of class and member descriptions. Overview Comment File Each application or set of packages that you are document­ ing can have its own overview documentation comment, kept in its own "source" file, that javadoc merges into the overview page that it generates. You typically include in this comment any documentation that applies to the entire application or set of packages. To create an overview comment file, you can name the file anything you want, typically overview.html, and place it anywhere, typically at the top level of the source tree. Notice that you can have multiple overview comment files for the same set of source files, in case you want to run javadoc multiple times on different sets of packages. For example, if the source files for the java.applet package are contained in /home/user/src/java/applet directory, you could create an overview comment file at /home/user/src/overview.html. The content of the overview comment file is one big docu­ mentation comment, written in HTML, like the package com­ ment file described previously. See that description for details. To reiterate, when writing the comment, you should make the first sentence a summary about the appli­ cation or set of packages, and not put a title or any other text between <body> and the first sentence. You can include overview tags; as with any documentation comment, all tags except {@link} must appear after the description. If you add a @see tag, it must have a fully-qualified name. When you run javadoc, you specify the overview comment file name with the -overview option. The file is then processed, similar to that of a package comment file: · Copies all content between <body> and </body> tags for processing. · Processes any overview tags that are present. · Inserts the processed text at the bottom of the overview page it generates, as shown in Overview Summary. · Copies the first sentence of the overview comment to the top of the overview summary page. Miscellaneous Unprocessed Files You can also include in your source any miscellaneous files that you want javadoc to copy to the destination directory. These typically include graphic files (for example, Java source (.java) and class (.class) files) and self-standing HTML files whose content would overwhelm the documentation comment of a normal Java source file. To include unprocessed files, put them in a directory called doc-files, which can be a subdirectory of any pack­ age directory. You can have one such subdirectory for each package. You might include images, example code, source files, .class files, applets, and HTML files. For example, if you want to include the image of a button but­ ton.gif in the java.awt.Button class documentation, you place that file in the /home/user/src/java/awt/doc-files/ directory. All links to these unprocessed files must be hard-coded, because javadoc does not look at the files; it only copies the directory and all its contents to the des­ tination. For example, the link in the Button.java doc comment might look like this: /** * This button looks like this: * <img src="doc-files/Button.gif"> */ Generated Files By default, javadoc uses a standard doclet that generates HTML-formatted documentation. This doclet generates the following kinds of files (where each HTML "page" corre­ sponds to a separate file). Notice that javadoc generates files with two types of names: those named after classes/interfaces, and those that are not (such as pack­ age-summary.html). Files in the latter group contain hyphens to prevent file name conflicts with those in the former group. Basic Content Pages · One class or interface page (classname.html) for each class or interface it is documenting. · One package page (package-summary.html) for each package it is documenting. javadoc includes any HTML text pro­ vided in a file named package.html in the package direc­ tory of the source tree. · One overview page (overview-summary.html) for the entire set of packages. This is the front page of the gener­ ated document. javadoc includes any HTML text provided in a file specified with the -overview option. Notice that this file is created only if you pass into javadoc two or more package names. For further explanation, see HTML Frames below. Cross-Reference Pages · One class hierarchy page for the entire set of packages (overview-tree.html). To view this, click on "Overview" in the navigation bar, then click on "Tree". · One class hierarchy page for each package (package- tree.html). To view this, go to a particular package, class or interface page; click "Tree" to display the hierarchy for that package. · One "use" page for each package (package-use.html) and a separate one for each class and interface (class- use/classname.html). This page describes what packages, classes, methods, constructors, and fields use any part of the given class, interface, or package. Given a class or interface A, its "use" page 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 package, class, or interface, then clicking on the "Use" link in the navigation bar. · A deprecated API page (deprecated-list.html) listing all deprecated names. (A deprecated name is not recommended for use, generally due to improvements, and a replace­ ment name is usually given. Deprecated APIs might be removed in future implementations.) · A serialized form page (serialized-form.html) for infor­ mation about serializable and externalizable classes. Each such class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. · An index (index-*.html) of all class, interface, con­ structor, field and method names, alphabetically arranged. This is internationalized for Unicode and can be generated as a single file or as a separate file for each starting character (such as A-Z for English). Support Files · A help page (help-doc.html) that describes the naviga­ tion bar and the above pages. You can provide your own custom help file to override the default using -help­ file. · One index.html file that creates the HTML frames for display. This is the file you load to display the front page with frames. This file itself contains no text content. · Several frame files (*-frame.html) containing lists of packages, classes and interfaces, used when HTML frames are being displayed. · A package list file (package-list), used by the -link and -linkoffline options. This is a text file, not HTML, and is not reachable through any links. · A style sheet file (stylesheet.css) that controls a lim­ ited amount of color, font family, font size, font style, and positioning on the generated pages. · A doc-files directory that holds any image, example, source code, or other files that you want copied to the destination directory. These files are not processed by javadoc in any manner, that is, any javadoc tags in them will be ignored. This directory is not generated unless it exists in the source tree. HTML Frames javadoc generates either two or three HTML frames, as shown in the figure below. When you pass source files (*.java) or a single package name as arguments into the javadoc command, it creates only one frame (C) in the left-hand column, that is, 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). This overview page has the file name, overview-summary.html. Thus, this file is created only if you pass in two or more package names. You can bypass frames by clicking on the "No Frames" link or entering at overview-summary.html. If you are unfamiliar with HTML frames, you should be aware that frames can have focus for printing and scrolling. To give a frame focus, click on it. Then, on many browsers the arrow keys and page keys will scroll that frame, and the print menu command will print it. ------------ ------------ |C| Detail | |P| Detail | | | | | | | | | | |-| | | | | |C| | | | | | | | | | | | | | ------------ ------------ javadoc *.java javadoc java.lang java.awt Load one of the following two files as the starting page depending on whether you want HTML frames or not: · index.html (for frames) · overview-summary.html (for no frames) Generated File Structure The generated class and interface files are organized in the same directory hierarchy as Java source files and class files. This structure is one directory per subpack­ age. For example, the document generated for the class java.applet.Applet would be located at java/applet/Applet.html. The file structure for the java.applet package follows, given that the destination directory is named apidocs. All files that contain the word "frame" appear in the upper-left or lower-left frames, as noted. All other HTML files appear in the right-hand frame. NOTE: Directories are shown in bold. The asterisks (*) indicate the files and directories that are omitted when the arguments to javadoc are source file names (*.java) rather than package names. Also, when arguments are source file names, package-list is created but is empty. The doc-files directory is not created in the destination unless it exists in the source tree. apidocs Top directory index.html Initial page that sets up HTML frames * overview-summary.html Packages with first sentence summaries overview-tree.html Class hierarchy for all packages deprecated-list.html Deprecated API for all packages serialized-form.html Serialized form for all packages * overview-frame.html All packages, used in upper-left frame allclasses-frame.html All package classes, lower-left frame help-doc.html User help--how pages are organized index-all.html Default index created w/o-splitindex index-files Directory created with -splitindex index-<number>.html Index files created with -splitindex package-list Package names--resolving external refs stylesheet.css HTML style sheet (fonts, colors, etc.) java Subpackage directory applet Subpackage directory Applet.html Page for Applet class AppletContext.html Page for AppletContext interface AppletStub.html Page for AppletStub interface AudioClip.html Page for AudioClip interface * package-summary.html 1st sentence summaries--package classes * package-frame.html Package classes, lower left-hand frame * package-tree.html Class hierarchy for this package package-use Where this package is used -files Directory holding image & example files class-use Directory holding pages API is used Applet.html Page for uses--Applet class AppletContext.html Page for uses--AppletContext interface AppletStub.html Page for uses--AppletStub interface AudioClip.html Page for uses--AudioClip interface API Signatures javadoc generates a signature at the start of each class, interface, field, constructor, and method description. This description is the declaration for that API item. For example, the signature for the Boolean class is: public final class Boolean extends Object implements Serializable and the signature for the Boolean.valueOf method is: public static Boolean valueOf(String s) javadoc can include the modifiers public, protected, pri­ vate, abstract, final, static, transient, and volatile, but not synchronized or native. These last two modifiers are considered implementation detail and not part of the API specification. Rather than relying on the keyword synchronized, APIs should document their concurrency semantics in the comment description, as in, for example, "a single Enumeration cannot be used by multiple threads concurrently". The document should not describe how to achieve these seman­ tics. As another example, while Hashtable should be thread-safe, there is no reason to specify that we achieve this by synchronizing all of its exported methods. We should reserve the right to synchronize internally at the bucket level, thus offering higher concurrency. Documentation Comments 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). These are also known as javadoc comments. A doc comment consists of the char­ acters between the characters /** that begin the comment and the characters */ that end it. The text can continue onto multiple lines. /** * This is the typical format of a simple documentation comment. */ To save space you can put a comment on one line: /** This comment takes up only one line. */ Placement of Comments Documentation comments are recognized only when placed immediately before class, interface, constructor, method, or field declarations (see the class example, method exam­ ple, and field example). Documentation comments placed in the body of a method are ignored. Only one documentation comment per declaration statement is recognized by the javadoc tool. A common mistake is to put an import statement between the class comment and the class declaration. Avoid this, as javadoc will ignore the class comment. /** * This is the class comment for the class Whatever. */ import com.sun; // MISTAKE - Important not to put statements here public class Whatever { } Comment Tags A comment is a description followed by tags. The descrip­ tion begins after the starting delimiter /** and continues until the tag section. The tag section starts with the first character @ that begins a line (ignoring leading asterisks and white space). The description cannot con­ tinue after the tag section begins. Any number of tags can exist, though some types of tags can be repeated while others cannot. This @see starts the tag section: /** * This is a doc comment. * @see java.lang.Object */ Standard and In-line Tags A tag is a special keyword within a doc comment that javadoc can process. javadoc has standard tags, which appear as @tag, and in-line tags, which appear within braces, as, for example, {@tag}. To be interpreted, a standard tag must appear at the beginning of a line, ignoring leading asterisks, white space, and comment sepa­ rator (/**). This means that you can use the @ character elsewhere in the text and it will not be interpreted as the start of a tag. If you want to start a line with the @ character and not have it be interpreted, use the HTML entity &#064;. Each standard tag has associated text, which includes any text following the tag up to, but not including, either the next tag, or the end of the doc com­ ment. An in-line tag is allowed and interpreted anywhere that text is allowed. The following example contains the standard tag @deprecated and in-line tag {@link}: /** * @deprecated As of JDK 1.1, replaced by{@link #setBounds(int,int,int,int)} */ Comments are written in HTML The text must be written in HTML so that comments can use HTML entities and HTML tags. You can use whichever ver­ sion of HTML your browser supports; the standard doclet is written to generate HTML 3.2-compliant code elsewhere (outside of the documentation comments) with the inclusion of cascading style sheets and frames. (Each generated file is prefaced with "HTML 4.0" because of the frame sets.) For example, entities for the less-than (<) and greater- than (>) symbols should be written &lt; and &gt;. Like­ wise, the ampersand (&) should be written &amp;. The bold HTML tag <b> is shown in the following example: /** * This is a <b>doc</b> comment. * @see java.lang.Object */ Leading Asterisks When javadoc parses a doc comment, leading asterisk (*) characters on each line are discarded; blanks and tabs preceding the initial asterisk (*) characters are also discarded. If you omit the leading asterisk on a line, all leading white space is removed. Therefore, you should not omit leading asterisks if you want leading white space to be kept, such as when indenting sample code with the <pre> tag. First Sentence 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 termina­ tor, or at the first tag. javadoc copies this first sen­ tence to the member summary at the top of the HTML page. Declaration with Multiple Fields java allows declaring multiple fields in a single statement, but this statement can have only one documenta­ tion comment, which is copied for all fields. Therefore, if you want individual documentation comments for each field, you must declare each field in a separate state­ ment. For example, the following documentation comment does not make sense when written as a single declaration and would be better handled as two declarations: /** * The horizontal and vertical distances of point (x,y) */ public int x, y; // Avoid this javadoc generates the following documentation from the above code: public int x The horizontal and vertical distances of point (x,y). public int y The horizontal and vertical distances of point (x,y). Use header tags carefully When writing documentation comments for members, it is best not to use HTML heading tags such as <h1> and <h2>, because javadoc creates an entire structured document and these structural tags can interfere with the formatting of the generated document. However, it is fine to use these headings in class and package comments to provide your own structure. Automatic Re-use of Method Comments Automatic re-use of method comments is also known as "inheriting comments". If a method in a class or inter­ face has no doc comment or tags, javadoc instead uses the comment and tags from a method it either overrides or implements, if any. This occurs in three cases: · When a method in a class overrides a method in a super­ class · When a method in an interface overrides a method in a superinterface · When a method in a class implements a method in an interface In the first two cases, if a method m() overrides another method, javadoc generates a subheading "Overrides" in the documentation for m(), with a link to the method it is overriding. In the third case, if a method m() in a given class imple­ ments a method in an interface, javadoc generates a sub­ heading "Specified by" in the documentation for m(), with a link to the method it is implementing. How does it search? For a method in class C, javadoc searches recursively through all interfaces that class C implements, then through all superclasses of C. For a method in interface I, it searches recursively through all of its superinterfaces. In each case, it copies the first comment that it finds. For the specification on documentation comments, see Chapter 18, "Documentation Comments," in the Java Language Specification, by James Gosling, Bill Joy, and Guy Steele. javadoc Tags javadoc parses special tags when they are embedded within a javadoc comment. These doc tags enable you to autogen­ erate a complete, well-formatted API from your source code. The tags start with an "at" sign (@) and are case- sensitive; that is, they must be typed with the uppercase and lowercase letters as shown. A tag must start at the beginning of a line (after any leading spaces and an optional asterisk) or it is treated as normal text. By convention, you should group tags with the same name together. For example, put all @see tags together. For information about tags might be introduced in future releases, see Proposed Tags. The current tags are: +-------------+-------------+ | Tag | Introduced | | | in JDK | +-------------+-------------+ |@author | 1.0 | |{@docRoot} | 1.3 | |@deprecated | 1.0 | |@exception | 1.0 | |{@link} | 1.2 | |@param | 1.0 | |@return | 1.0 | |@see | 1.0 | |@serial | 1.2 | |@serialData | 1.2 | |@serialField | 1.2 | |@since | 1.1 | |@throws | 1.2 | |@version | 1.0 | +-------------+-------------+ @author name-text Adds an "Author" entry with the specified name-text to the generated docs when the -author option is used. A doc comment can contain multiple @author tags. You can specify one name per @author tag or multiple names per tag. In the former case, javadoc inserts a comma (,) and space between names. In the latter case, the entire text is copied to the generated document without being parsed. Therefore, use multiple names per line if you want a localized name separator other than a comma. {@docRoot} Represents the relative path to the generated docu­ ment's (destination) root directory from any gener­ ated page. It is useful when you want to include a file, such as a copyright page or company logo, that you want to reference from all generated pages. Linking to the copyright page from the bot­ tom of each page is common. This {@docRoot} tag can be used both on the command line and in a doc comment: 1. On the command line, where the header/footer/bottom are defined: javadoc -bottom '<a href="{@docRoot}/copy­ right.html">Copyright</a>' 2. In a doc comment: /** * See the <a href="{@docRoot}/copyright.html">Copyright</a>. */ The reason this tag is needed is because the gener­ ated docs are in hierarchical directories, as deep as the number of subpackages. This expression: <a href="{@docRoot}/copyright.html"> would resolve to: <a href="../../copyright.html"> ... for java/lang/Object.java and <a href="../../../copyright.html"> ... for java/lang/ref/Reference.java @deprecated deprecated-text Adds a comment indicating that this API should no longer be used (even though it might continue to work). javadoc moves the deprecated-text ahead of the description, placing it in italics and preced­ ing it with a bold warning: "Deprecated". The first sentence of deprecated-text should at least tell the user when the API was deprecated and what to use as a replacement. javadoc copies just the first sentence to the summary section and index. Subsequent sentences can also explain why it has been deprecated. You should include a {@link} tag (for javadoc 1.2 or later) that points to the replacement API: · For javadoc 1.2, use a {@link} tag. This creates the link in-line, where you want it. For example: /** * @deprecated As of JDK 1.1, replaced by * {@link #setBounds(int,int,int,int)} */ · For javadoc 1.1, the standard format is to create a @see tag (which cannot be in-line) for each @deprecated tag. For more about deprecation, 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 below, but generates an in-line link rather than placing the link in the "See Also" sec­ tion. This tag begins and ends with curly braces to separate it from the rest of the in-line text. If you need to use "}" inside the label, use the HTML entity notation &#125;. There is no limit to the number of {@link} tags allowed in a sentence. You can use this tag in the description part of a documentation comment or in the text portion of any tag (such as @deprecated, @return, or @param). 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 (assuming it refers to another class in the same package): Use the <a href="Component.html#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 can continue on the next line. @return description Adds a "Returns" section with the description text. This text should describe the return type and per­ missible range of values. @see reference Adds a "See Also" heading with a link or text entry that points to reference. A doc comment can con­ tain any number of @see tags, which are all grouped under the same heading. The @see tag has three variations; the third form below is the most com­ mon. @see string Note: This form is broken in JDK 1.2 (prints none of the quoted text) but is fixed in JDK 1.2.2. Adds a text entry for string. No link is generated. The string is a book or other reference to informa­ tion not available by URL. javadoc distinguishes this from the previous cases by looking for a dou­ ble-quote (") as the first character. For example: @see "The Java Programming Language" This generates text such as: See Also: "The Java Programming Language" @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 distin­ guishes this from other cases by looking for a less-than symbol (<) as the first character. For example: @see <a href="spec.html#section">Java Spec</a> This generates a link such as: See Also: Java Spec @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 as the visible text, suit­ ably shortened (see How a Name Is Displayed). Use the label when you want the visible text to be abbreviated or different from the name. In JDK 1.2, only the name but not the label auto­ matically appears in <code> HTML tags. Starting with JDK 1.2.2, the <code> is always included around the visible text, whether or not a label is used. · package.class#member is any valid name in the Java Language that is referenced (package, class, interface, constructor, method, or field name), except that you replace the dot ahead of the mem­ ber name with a hash character (#). If this name is in the documented classes, javadoc automati­ cally creates 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 argument is described at greater length below under Specifying a Name. · label is optional text that is visible as the link's label. The label can contain white space. If a label is omitted, then package.class.member will appear, suitably shortened relative to the current class and package (see How a Name Is Dis­ played). · A space is the delimiter between pack­ age.class#member and label. A space inside parentheses does not indicate the start of a label, so spaces can be used between parameters in a method. In the example below, an @see tag (in the Character class) refers to the equals method in the String class. The tag includes both arguments, that is, the name "String#equals(Object)" and the label "equals": /** * @see String#equals(Object) equals */ The standard doclet produces HTML something like this: <dl> <dt><b>See Also:</b> <dd><a href="../../java/lang/String#equals\ (java.lang.Object)"><code>equals</code></a> </dl> The above looks something like this in a browser, where the label is the visible link text: See Also: equals Specifying a Name: This package.class#member name can be either fully qualified, such as java.lang.String#toUpperCase(), or not, such as String#toUpperCase() or #toUpperCase(). If less than fully-qualified, javadoc uses the normal Java compiler search order to find it, further described below in Search order for @see. The name can con­ tain whitespace within parentheses, such as between method arguments. The advantage to providing shorter, "partially- qualified" names is that they require less typing and make less clutter in the source code. The fol­ lowing table shows 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. +-----------------------------------------------------------+ | Typical forms for @see package.class#member | +-----------------------------------------------------------+ |Referencing a member of the current class | |@see #field | |@see #method(Type, Type,...) | |@see #method(Type argname, Type argname,...) | |Referencing another class in the current or imported | |packages | |@see Class#field | |@see Class#method(Type, Type,...) | |@see Class#method(Type argname, Type argname,...) | |@see Class | |Referencing another package (fully qualified) | |@see package.Class#field | |@see package.Class#method(Type, Type,...) | |@see package.Class#method(Type argname, Type argname,...) | |@see package.Class | |@see package | +-----------------------------------------------------------+ The following notes apply to the above table: · The first set of forms (with no class or package) will cause javadoc to search only through the current class's hierarchy. It finds a member of the current class or interface, one of its super­ classes or superinterfaces, or one of its enclos­ ing classes or interfaces (search steps 1-3). It will not search the rest of the current package or other packages (search steps 4-5). · If any method or constructor is entered as a name with no parentheses, such as getValue, and if no field with the same name exists, javadoc will correctly create a link to it, but will print a warning message reminding you to add the paren­ theses and arguments. If this method is over­ loaded, javadoc links to the first method that its search encounters, which is unspecified. · Inner classes must be specified as outer.inner, not only inner, for all forms. · As stated, 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, pack­ ages, and subpackages. The hash character is absolutely necessary in the forms above where it is the first character. However, in other forms, javadoc is generally lenient and allows a dot if it does not produce an ambiguity, though it does print a warning. Search Order for @see: javadoc will process an @see tag that appears in a source file (.java), package file (package.html), or overview file (overview.html). In the latter two files, fully qualify the name you supply with @see. In a source file, you can specify a name that is fully qualified or partially qualified. When javadoc encounters an @see tag in a .java file that is not fully qualified, it searches for the specified name in the same order as the Java com­ piler would (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. 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 searches 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,sincethatisautomatically imported by all programs. javadoc will not necessarily look in subclasses, nor will it look in other packages even if their documentation is being generated in the same run. For example, if the @see tag is in java.awt.event.KeyEvent class and refers to a name in the java.awt package, javadoc will not look in that package unless that class imports it. How a Name is Displayed: If label is omitted, then package.class.member will appear. In general, it will be suitably shortened relative to the current class and package. By "shortened", we mean javadoc will display only the minimum name necessary. For example, if the String.toUpperCase() method con­ tains references to a member of the same class and to a member of a different class, the class name will be displayed only in the latter case: Type Example Displays As of Ref- erence @see tag @see toLowerCase() refers String#toLowerCase() (omits the class name) to member of the same class @see @see Character.toLowerCase(char) tag Character#toLowerCase(char) (includes the class name) refers to member of a differ- ent class Examples of @see: The comment to the right shows how the name would be displayed if the @see tag is in a class in another package, such as java.applet.Applet: Example See also: @see java.lang.String // String @see java.lang.String The String class // The String class @see String // String @see String#equals(Object) // String.equals(Object) @see String#equals // String.equals\ (java.lang.Object) @see java.lang.Object#wait(long) // java.lang.Object.\ wait(long) @see Character#MAX_RADIX // Character.MAX_RADIX @see <a href="spec.html">Java Spec</a> // Java Spec @see "The Java Programming Language" // "The Java Programming \ Language" You can extend @see to link to classes not being docu­ mented by using the -link option. Notice that this works only for classes that are referenced in a particular way as described at How a Class Must Be Referenced. @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 soft­ ware 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 com­ ment 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 Serializ­ able Fields and Data for a Class," Section 1.6 of the Java Object Serialization Specification. Also see the "Serialization FAQ," which covers the ques­ tions, "Why does the javadoc standard doclet gener­ ate many warnings about missing @serial and/or @serialData tags?" and "Why do I see javadoc warn­ ings stating that I am missing @serial tags for private fields if I am not running javadoc with the -private switch?" @serialField field-name field-type field-description Documents an ObjectStreamField component of a Seri­ alizable class's 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 writ­ ten 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 documenta­ tion, with the class-name and description text. The class-name is the name of the exception that can 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 ver­ sion-text to the generated docs when the -version option is used. The text has no special internal structure. A doc comment can contain at most one @version tag. Version normally refers to the ver­ sion of the software (such as the JDK) that con­ tains this class or member. Where Tags Can Be Used The following sections describe where the tags can be used. Notice that these four tags can be used in all doc comments: @see, @link, @since, @deprecated. Overview Documentation Tags Overview tags are tags that can appear in the documenta­ tion comment for the overview page, which resides in the source file typically named (overview.html). As in any other documentation comments, these tags must appear after the description. NOTE: The {@link} tag has a bug in overview documents in JDK 1.2. Text appears properly but has no link. +--------------+ |Overview Tags | +--------------+ |@see | |{@link} | |@since | +--------------+ Package Documentation Tags Package tags are tags that can appear in the documentation comment for a package (which resides in the source file named package.html). +-------------+ |Package Tags | +-------------+ |@see | |{@link} | |@since | |@deprecated | +-------------+ Class and Interface Documentation Tags The following are tags that can appear in the documenta­ tion 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 1.15, 08/03/00 * @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 documen­ tation 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 documen­ tation 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) { } Command Line Argument File To shorten or simplify the javadoc command, you can spec­ ify one or more files that themselves contain one source filename or package name per line. When executing javadoc, pass in the filename with the '@' leading charac­ ter to specify it as a file list. When javadoc encounters an argument beginning with the character it operates on the names in that file as if they were on the command line. For example, you can list all of the package names in a file named packages. This file might look like: com.my.package1 com.my.package2 com.my.package3 You could then run javadoc with: example% javadoc -d apidocs @packages

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 pro­ vides 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-insensi­ tive, though their arguments can be case-sensitive. The options are: -1.1 -header -package -author -help -private -bootclasspath -helpfile -protected -bottom -J -public -charset -link -serialwarn -classpath -linkoffline -sourcepath -d -locale -splitindex -docencoding -nodeprecated -stylesheetfile -doclet -nodeprecatedlist -title -docletpath -nohelp -use -doctitle -noindex -verbose -encoding -nonavbar -version -extdirs -notree -windowtitle -footer -overview -group javadoc Options -overview path/filename Specifies that javadoc should retrieve the text for the overview documentation from the "source" file specified by path/filename and place it on the Overview page (overview-summary.html). The path/filename is relative to the -sourcepath. While you can use any name you want for filename and place it anywhere you want for path, a typical thing to do is to name it overview.html and place it in the source tree at the directory that con­ tains the topmost package directories. In this location, no path is needed when documenting packages, since -sourcepath will point to this file. For example, if the source tree for the java.lang package is /src/classes/java/lang/, then you could place the overview file at /src/classes/overview.html. See Real World Exam­ ple. For information about the file specified by path/filename, see overview comment file. Notice that the overview page is created only if you pass into javadoc two or more package names. For further explanation, see HTML Frames. -public Shows only public classes and members. -protected Shows only protected and public classes and mem­ bers. 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 stan­ dard 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 classpathlist 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, have a flat destination directory struc­ ture, do not contain inherited API, do not use HTML frames, and do not support inner classes. This option also automatically splits the index into a separate file for each letter of the alphabet. If you want this appearance, this option has the advantage over javadoc 1.1 of having some bugs fixed. Not all options work with the -1.1 option. To find out which other options are available, execute: example% javadoc -1.1 -help The -footer option shown in this list is function­ ally the same as the -bottom option described else­ where on this page. The -title option is function­ ally the same as -doctitle. -sourcepath sourcepathlist Specifies the search paths for finding source files (.java) when passing package names into the javadoc command. Notice that you can use the -sourcepath option only when passing package names into the javadoc command; it does not locate .java files passed into the javadoc command. (To locate .java files, cd to that directory or include the path ahead of each file, as shown at Documenting One or More Classes.) If -sourcepath is omitted, javadoc uses the class path to find the source files (see -classpath). Therefore, the default -sourcepath is the value of class path. If -classpath is omitted and you are passing package names into javadoc, it looks in the current directory (and subdirectories) for the source files. Set sourcepathlist to the root directory of the source tree for the package you are documenting. For example, suppose you want to document a package called com.mypackage whose source files are located at: /home/user/src/com/mypackage/*.java In this case, you would specify the source path to /home/user/src, the directory that contains com/mypackage, and then supply the package name com.mypackage: example% javadoc -sourcepath /home/user/src/ com.mypackage This is easy to remember by noticing that if you concatenate the value of the source path and the package name together and change the dot to a slash "/", you end up with the full path to the package: /home/user/src/com/mypackage -classpath classpathlist Specifies the paths where javadoc looks for refer­ enced classes (.class); these are the documented classes plus any classes referenced by those classes. javadoc searches in all subdirectories of the specified paths. The class path list can con­ tain multiple paths by separating them with a colon. Follow the instructions in class path docu­ mentation for specifying classpathlist. If -sourcepath is omitted, javadoc uses -classpath to find the source files as well as class files (for backward compatibility). Therefore, if you want to search for source and class files in sepa­ rate paths, use both -sourcepath and -classpath. For example, if you want to document com.mypackage, whose source files reside in the directory /home/user/src/com/mypackage, and if this package relies on a library in /home/user/lib, you would specify: example% javadoc -classpath /home/user/lib -sourcepath \ /home/user/src com.mypackage As with other tools, if you do not specify -class­ path, javadoc uses the CLASSPATH environment vari­ able, if it is set. If both are not set, javadoc searches for classes from the current directory. For an in-depth description of how javadoc uses -classpath to find user classes as it relates to extension classes and bootstrap classes, see How Classes Are Found. -bootclasspath classpathlist Specifies the paths where the boot classes reside. These are nominally the Java platform classes. The bootclasspath is part of the search path javadoc will use to look up source and class files. See How Classes Are Found 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 uses 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 mil­ liseconds to parse each java source file. -locale language_country_variant Specifies the locale that javadoc uses when gener­ ating documentation. The argument is the name of the locale, as described in java.util.Locale docu­ mentation, 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 in which to process the gener­ ated documentation, then you would use this flag as follows: example% javadoc -J-Xmx32m -J-Xms32m com.mypackage 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 fol­ lowing generates the documentation for the com.mypackage package and saves the results in the /home/user/doc/ directory: example% javadoc -d /home/user/doc com.mypackage -use 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 given 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, look at what might appear on the "Use" page for String. The getName() method in the java.awt.Font class returns type String. There­ fore, getName() uses String, and you will find that method on the "Use" page for String. Notice that this page documents only uses of the API, not the implementation. If a method uses String in its implementation but does not take a string as an argument or return a string, that is not considered a "use" of String. You can access the generated "Use" 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, alpha­ betically, one file per letter, plus a file for any index entries that start with non-alphabetical characters. -windowtitle title 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 cannot properly interpret them. Any internal quotation marks within title might have to be escaped. If -windowtitle is omitted, javadoc uses the value of -doctitle for this option. -doctitle title Specifies the title to be placed near the top of the overview summary file. The title is placed as a centered, level-one heading directly beneath the upper navigation bar. title can contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within title might have to be escaped. -title title This option no longer exists. It existed only in Beta versions of javadoc 1.2. It has been renamed to -doctitle. This option was renamed to make it clear that it defines the document title rather than the window title. -header header 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. header can con­ tain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quota­ tion marks within header might have to be escaped. -footer footer Specifies the footer text to be placed at the bot­ tom of each output file. The footer is placed to the right of the lower navigation bar. footer can contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within footer might have to be escaped. -bottom text Specifies the text to be placed at the bottom of each output file. The text is placed at the bottom of the page, below the lower navigation bar. text can contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within text might have to be escaped. -link docURL Creates links to already existing javadoc-generated documentation of external referenced classes. The argument docURL is the URL for the javadoc-gener­ ated external documentation you want to link to. This location can be a relative or absolute URL. In other words, this option enables you to link to classes referenced by your code but not documented in the current javadoc run. For these links to go to valid pages, you must know where those HTML pages are located and specify that location with docURL. This allows, for instance, third party documentation to link to java.* documentation on http://java.sun.com. Another use is for cross- links between sets of packages: Execute javadoc on one set of packages, then run javadoc again on another set of packages, creating links both ways between both sets. A third use is as a "hack" to update docs: Execute javadoc on a full set of pack­ ages, then run javadoc again on only the smaller set of changed packages, so that the updated files can be inserted back into the original set. (This is done to save time, but can be tricky; if you add or remove API from the subset, there will be miss­ ing or broken links in the index.) Use the -link option as follows: · Omit the -link option for javadoc to create links only to API within the documentation it is gener­ ating in the current run. (Without the -link option, javadoc does not create links to documen­ tation for external references, because it does not know if, or where, that documentation exists.) · Include the -link option for javadoc to also cre­ ate links to documentation at location docURL for external referenced classes. Notice that if the URL is on the World Wide Web, javadoc must have a web connection in order to access the package-list when generating the docu­ mentation. If you do not have access, use -linkof­ fline instead. How a Class Must be Referenced For a link to an external referenced class to actu­ ally appear, the class must be referenced in a par­ ticular way. It is not sufficient for it to be referenced in the body of a method. It must be referenced in either an import statement or in a declaration. Here are examples of how the class java.lang.SecurityManager can be referenced: · In an explicit import statement: import java.lang.SecurityManager; A wildcard import statement does not work (such as importjava.lang.*). · In the return type or parameter type of a method: void foo(SecurityManager sm) {} · In an implements, extends or throws statement: public abstract class MyClass extends Securi­ tyManager {} An important corollary is that when you use the -link option, there will probably be many links that do not appear due to this constraint. (The text would appear without a hypertext link.) The only way to find the missing links would be by visual inspection. The most innocuous way to prop­ erly reference a class and thereby add the link would be to import that class, as shown above. Package List The -link option requires that a file named pack­ age-list, which is generated by javadoc, exist at the URL you specify with -link. The package-list file is a simple text file that lists the names of packages documented at that location. How javadoc uses the package list is described below. For example, 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 It starts out as follows: java.applet java.awt java.awt.color java.awt.datatransfer java.awt.dnd java.awt.event java.awt.font etc. 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 that package 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 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 does not check that these pages exist, only that the pack­ age-list exists. The package-list file is created but is empty if the argument to javadoc is source files rather than packages. For example, the following command causes javadoc to look for a package-list file at the given URL, reads in the package names in that file, and then uses the given URL when adding links to API in those external packages: example% javadoc -link \ http://java.sun.com/products/jdk/1.2/docs/api com.mypackage Multiple Links You can supply multiple-link options to link to any number of external generated documents. Known Bug: Javadoc 1.2 has a known bug that prevents you from supplying more than one -link command. This should be fixed in a future release. Specify a different link option for each external document to link to: example% javadoc -link docURL1 -link docURL2 ... \ -link docURLn com.mypackage where docURL1, docURL2, ... docURLn point respec­ tively to the roots of external documents, each of which contains a file named package-list. Cross-links Notice that "bootstrapping" might be required when cross-linking two or more documents that have not been previously generated. In other words, if package-list does not exist for either document, when you run javadoc on the first document, the package-list does not yet exist for the second doc­ ument. Therefore, to create the external links, rree-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 if you are 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. Updating Docs The third use for the -link option is useful if your project has dozens or hundreds of packages; if you have already run javadoc on the entire tree; and now, in a separate run, you want to quickly make some small changes and re-run javadoc on just a small portion of the source tree. This is some­ what of a hack in that it works properly only if your changes are only to doc comments and not to signatures. If you were to add, remove, or change any signatures from the source code, then broken links could show up in the index, package tree, inherited member lists, use page, or other places. First, you create a new destination directory for this new small run and set -link and -d to that same relative path. If the original docs are in a directory named html: example% javadoc -d update -linkoffline . html com.mypackage When javadoc is done, copy these generated files in update over the original files in html. 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 cur­ rent run, while other links will potentially go to pages not generated in the current run. -linkoffline docURL packagelistLoc This option is a variation of the -link option. Both options create links to documentation for external referenced classes, where the classes must be referenced as described above in How a Class Must Be Referenced. You must use the -linkoffline option instead of -link if, at the time you run javadoc, the external document's package-list file does not exist at the docURL location (is "offline") but exists at a dif­ ferent location packageListLoc (typically local). This can happen when the shell in which you are running javadoc does not have web access to the docURL. Thus, if docURL is accessible only on the World Wide Web, -linkoffline removes the constraint that javadoc must have a web connection when gener­ ating the documentation. Examples are given below. You can specify multiple -linkoffline options in a given javadoc run. (Prior to 1.2.2, it could be specified only once.) The arguments are: · docURL: The URL for the root location of the external javadoc-generated documentation to which you want to link. This location can be an abso­ lute or relative URL. If it is relative, make it relative to the destination directory (specified with -d). · packagelistLoc: The location to the directory containing the package-list file for the external documentation. This can be a URL (http: or file:) or file path, and can be absolute or rela­ tive. If relative, make it relative to the cur­ rent directory from where javadoc was run. Do not include the package-list filename. For example, if you want to link to the java.lang package at http://java.sun.com/prod­ ucts/jdk/1.3/docs/api, but your shell does not have web access, then you could access the package-list file using http://java.sun.com/prod­ ucts/jdk/1.3/docs/api/package-list, save it to a local directory, and point to this local copy with packagelistLoc. If a package-list file does not yet exist, but you know what package names your document will link to, you can create your own copy of this file by hand and specify its path with packagelistLoc. This is useful when you need to generate documentation that links to new external documentation whose package names you know, but which is not yet published. This is also a way of creating a package-list file for linking to documentation generated with javadoc 1.0 or 1.1, earlier versions where package-list files were not generated. Two companies can share their unpublished package- list files, enabling them to release their cross- linked documentation simultaneously. As shown below, to use this option, specify docURL1, the location of the javadoc-generated doc­ umentation for external referenced classes, and packagelistLoc1, the location of its package-list file. Include -linkoffline once for each generated document you want to refer to (each option is shown on a separate line for clarity): example% javadoc -linkoffline docURL1 packagelistURL1 \ -linkoffline docURL2 packagelistURL2 \ ... For example, the following command adds links pointing to a document (whose root is specified by the first argument), for packages listed in the /jdk/package-list file (as specified by the second argument). It generates documentation for the com.mypackage package. % javadoc -linkoffline \ http://java.sun.com/products/jdk/1.3/docs/api \ /jdk com.mypackage -group groupheading packagepattern:packagepattern:... Separates packages on the overview page into what­ ever 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 speci­ fied 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 wild­ card 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 pack­ ages 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 Pack­ ages". 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: example% 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 -nodepre­ catedlist does, plus it does not generate any dep­ recated API throughout the rest of the documenta­ tion. This is useful when writing code and you do not 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. (How­ ever, 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. -nosince Omits from the generated docs the "Since" sections associated with the @since tags. -notree Omits the class/interface hierarchy from the gener­ ated 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 effect on the "bottom" option. The -nonavbar option is use­ ful when you are interested only in the content and have no need for navigation, such as converting the files to PostScript or PDF for print only. -helpfile path/filename Specifies the path of an alternate help file path/filename 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. The file name can be any name and is not restricted to help-doc.html; javadoc will adjust the links in the navigation bar accordingly. For example: example% javadoc -helpfile /home/doc/myhelp.html java.awt -stylesheetfile path/filename Specifies the path of an alternate HTML stylesheet file. Without this option, javadoc automatically creates a stylesheet file, stylesheet.css, that is hard-coded in javadoc. This option enables you to override this default. The file name can be any name and is not restricted to stylesheet.css. For example: example% javadoc -stylesheetfile \ /home/doc/mystylesheet.css java.awt -serialwarn Generates compile-time warnings for missing @serial tags. By default, javadoc 1.2.2 (and later ver­ sions) generates no serial warnings. (This is a reversal from earlier versions.) Use this option to display the serial warnings, which helps to properly document default serializable fields and writeExternal methods. -charset name Specifies the HTML character set for this document. For example: % javadoc -charset "iso-8859-1" mypackage would insert the following line in the head of every generated page: <META http-equiv="Content-Type" content="text/html; charset=iso-885 9-1"> This META tag is described in the HTML standard (4197265 and 4137321). -docencoding name Specifies the encoding of the generated HTML files. 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 /home/src/java/awt/*java. The destination directory is /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 sev­ eral identifiers (separated by dots), each identifier rep­ resents 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. You cannot use wildcards to specify groups of packages. · Case 1 Changing to the package directory: Change to the parent directory of the fully qualified package. Then run javadoc, supplying names of one or more packages you want to document: example% cd /home/src/ example% javadoc -d /home/html java.awt java.awt.event · Case 2 From any directory: In this case, it does not matter what the current directory is. Run javadoc sup­ plying -sourcepath with the parent directory of the fully qualified package, and supply names of one or more packages you want to document: example% javadoc -d /home/html -sourcepath /home/src \ java.awt java.awt.event 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 (/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 The second way to run javadoc is by passing in one or more source files (.java). 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. Relative paths are relative to the current directory. The -sour­ cepath option is ignored when passing in source files. You can use command line wildcards, such as asterisk (*), to specify groups of classes. · Case 1 Changing to the source directory: Change to the directory holding the .java files. Then run javadoc, supplying names of one or more source files you want to document. example% cd /home/src/java/awt example% javadoc -d /home/html Button.java Canvas.java \ Graphics*.java This example generates HTML-formatted documentation for the classes Button, Canvas, and classes beginning with Graphics. Because source files rather than package names were passed in as arguments to javadoc, the docu­ ment has two frames, for the list of classes and the main page. · Case 2 Changing to the package root directory: This is useful for documenting individual source files from dif­ ferent subpackages off the same root. Change to the package root directory, and supply the source files with paths from the root. example% cd /home/src/ example% javadoc -d /home/html java/awt/Button.java \ java/applet/Applet.java This example generates HTML-formatted documentation for the classes Button and Applet. · Case 3 From any directory: In this case, it does not matter what the current directory is. Run javadoc, sup­ plying the absolute path (or path relative to the cur­ rent directory) to the .java files you want to document: example% javadoc -d /home/html /home/src/java/awt/Button.java \ /home/src/java/awt/Graphics*.java This example generates HTML-formatted documentation for the class Button and classes beginning with Graphics. Documenting Both Packages and Classes You can document entire packages and individual classes at the same time. Here is an example that mixes the two pre­ vious examples. You can use -sourcepath for the path to the packages but not for the path to the individual classes: example% javadoc -d /home/html -sourcepath /home/src java.awt \ /home/src/java/applet/Applet.java This example generates HTML-formatted documentation for the package java.awt and class Applet. (javadoc deter­ mines the package name for Applet from the package decla­ ration, if any, in the Applet.java source file.) Real World Example javadoc has many useful options, some of which are more commonly used than others. Here is an example of a com­ mand used to run javadoc on the Java platform API, using 180MB of memory to generate the documentation for the approximately 1500 public and protected classes in the Java 2 Platform, Standard Edition, v1.2. The same example is shown twice, first as executed on the command line, then as executed from a makefile. It uses absolute paths in the option arguments, which enables the same javadoc command to be run from any directory. Command Line Example This command line example is over 900 characters, which is too long for some shells, such as DOS. You can write a shell script instead to execute this command. % javadoc -sourcepath /java/jdk/src/share/classes\ -overview /java/jdk/src/share/classes/overview.html\ -d /java/jdk/build/api \ -use \ -splitIndex \ -windowtitle 'Java 2 Platform v1.2 API Specification'\ -doctitle 'Java<sup><font size="-2">TM</font>\ </sup> 2 Platform v1.2 API Specification'\ -header '<b>Java 2 Platform </b><br><font size="-1">v1.2</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-2001\ Sun Microsystems, Inc., 901 San Antonio Road,<br>\ Palo Alto, California, 94303, U.S.A.\ All Rights Reserved.</font>' \ -group "Core Packages" "java.*:com.sun.java.*:org.omg.*"\ -group "Extension Packages" "javax.*"\ -J-Xmx180m \ @filelist where filelist is the name of a file containing the packages to process, such as java.applet java.lang. None of the options should contain any newline characters between the single quotes. (For exam­ ple, if you copy and paste this example, delete the newline characters from the -bottom option.) See the other notes listed below. Makefile Example This is an example of a GNU makefile. For an example of a Windows makefile, see Creating a makefile for Windows. example% javadoc -sourcepath $(SRCDIR)\ /* Sets path for source files */ -overview $ (SCRDIR) /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) \ /* Core heading for overview page */ -group $(GROUPEXT) \ /* Ext heading for 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 2 Platform v1.2 API Specification' DOCTITLE = 'Java<sup><font size="-2">TM</font></sup> 2 Platform 1.2 \ API Specification' HEADER = '<b>Java 2 Platform</b><br><font size="-1">v1.2</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-2001 Sun Microsystems, Inc. 901 San \ Antonio Road,<br>Palo Alto, California, 94303, U.S.A. \ </font>' GROUPCORE = '"Core Packages" "java.*:com.sun.java.*:org.omg.*" GROUPEXT = '"Extension Packages" "javax.*"' SRCDIR = '/java/jdk/1.2/src/share/classes' Single quotes are used to surround makefile argu­ ment. NOTE: · If you omit the -windowtitle option, javadoc copies the doc title to the window title. The -windowtitle text is basically the same as the -doctitle but without HTML tags, to prevent those tags from appearing as raw text in the window title. · If you omit the -footer option, as done here, javadoc copies the header text to the footer. · Other important options you might want to use but not needed in this example are -classpath and -link.

ENVIRONMENT VARIABLES

CLASSPATH Environment variable that provides the path that javadoc uses to find user class files. This environment vari­ able is overridden by the -classpath option. Separate your directories with a colon, as for example: .:/home/classes:/usr/local/java/classes TROUBLESHOOTING There is currently no documentation for javadoc error mes­ sages. Troubleshooting tips can be found on the Javadoc FAQ.

SEE ALSO

javac(1), java(1), jdb(1), javah(1), javap(1), See (or search java.sun.com) for the following: The Javadoc Home Page @ http://java.sun.com/prod­ ucts/jdk/javadoc/index.html Javadoc Enhancements @ http://java.sun.com/j2se/1.3/docs/tooldocs/javadoc/index.html Javadoc FAQ @ http://java.sun.com/prod­ ucts/jdk/javadoc/faq.html How to Write Doc Comments for Javadoc @ http://java.sun.com/products/jdk/javadoc/writ­ ingdoccomments.html How Classes Are Found @ http://java.sun.com/j2se/1.3/docs/tooldocs/find­ ingclasses.html#srcfiles 3 Jan 2001 javadoc(1)