Javadoc Task

## Javadoc/Javadoc2

### Description

Generates code documentation using the javadoc tool.

The source directory will be recursively scanned for Java source files to process but only those matching the inclusion rules, and not matching the exclusions rules will be passed to the javadoc tool. This allows wildcards to be used to choose between package names, reducing verbosity and management costs over time. This task, however, has no notion of "changed" files, unlike the javac task. This means all packages will be processed each time this task is run. In general, however, this task is used much less frequently.

This task works seamlessly between different javadoc versions (1.1, 1.2 and 1.4), with the obvious restriction that the 1.2 attributes will be ignored if run in a 1.1 VM.

NOTE: since javadoc calls System.exit(), javadoc cannot be run inside the same VM as ant without breaking functionality. For this reason, this task always forks the VM. This overhead is not significant since javadoc is normally a heavy application and will be called infrequently.

NOTE: the packagelist attribute allows you to specify the list of packages to document outside of the Ant file. It's a much better practice to include everything inside the build.xml file. This option was added in order to make it easier to migrate from regular makefiles, where you would use this option of javadoc. The packages listed in packagelist are not checked, so the task performs even if some packages are missing or broken. Use this option if you wish to convert from an existing makefile. Once things are running you should then switch to the regular notation.

DEPRECATION: the javadoc2 task simply points to the javadoc task and it's there for back compatibility reasons. Since this task will be removed in future versions, you are strongly encouraged to use javadoc instead.

In the table below, 1.1 means available if your current Java VM is a 1.1 VM, 1.2 for either 1.2 or 1.3 and 1.4 for a 1.4 Java VM. 1.2+ means any VM of at least version 1.2.

### Parameters

Attribute | Description | Availability | Required
sourcepath | Specify where to find source files | all | At least one of the three or nested `<sourcepath>`, `<fileset>` or `<packageset>`
sourcepathref | Specify where to find source files by reference to a PATH defined elsewhere. | all
sourcefiles | Comma separated list of source files | all
destdir | Destination directory for output files | all | Yes, unless a doclet has been specified.
maxmemory | Max amount of memory to allocate to the javadoc VM | all | No
packagenames | Comma separated list of package files (with terminating wildcard) | all | No
packageList | The name of a file containing the packages to process | 1.2+ | No
classpath | Specify where to find user class files | all | No
Bootclasspath | Override location of class files loaded by the bootstrap class loader | 1.2+ | No
classpathref | Specify where to find user class files by reference to a PATH defined elsewhere. | all | No
bootclasspathref | Override location of class files loaded by the bootstrap class loader by reference to a PATH defined elsewhere. | 1.2+ | No
Extdirs | Override location of installed extensions | 1.2+ | No
Overview | Read overview documentation from HTML file | 1.2+ | No
access | Access mode: one of `public`, `protected`, `package`, or `private` | all | No (default `protected`)
Public | Show only public classes and members | all | No
Protected | Show protected/public classes and members (default) | all | No
Package | Show package/protected/public classes and members | all | No
Private | Show all classes and members | all | No
Old | Generate output using JDK 1.1 emulating doclet | 1.2 | No
Verbose | Output messages about what Javadoc is doing | 1.2+ | No
Locale | Locale to be used, e.g. en_US or en_US_WIN | 1.2+ | No
Encoding | Source file encoding name | all | No
Version | Include @version paragraphs | all | No
Use | Create class and package usage pages | 1.2+ | No
Author | Include @author paragraphs | all | No
Splitindex | Split index into one file per letter | 1.2+ | No
Windowtitle | Browser window title for the documentation (text) | 1.2+ | No
Doctitle | Include title for the package index(first) page (html-code) | 1.2+ | No
Header | Include header text for each page (html-code) | 1.2+ | No
Footer | Include footer text for each page (html-code) | 1.2+ | No
bottom | Include bottom text for each page (html-code) | 1.2+ | No
link | Create links to javadoc output at the given URL | 1.2+ | No
linkoffline | Link to docs at <url> using package list at <url2> - separate the URLs by using a space character. | 1.2+ | No
group | Group specified packages together in overview page. The format is as described below. | 1.2+ | No
nodeprecated | Do not include @deprecated information | all | No
nodeprecatedlist | Do not generate deprecated list | 1.2+ | No
notree | Do not generate class hierarchy | all | No
noindex | Do not generate index | all | No
nohelp | Do not generate help link | 1.2+ | No
nonavbar | Do not generate navigation bar | 1.2+ | No
serialwarn | Generate warning about @serial tag | 1.2+ | No
helpfile | Specifies the HTML help file to use | 1.2+ | No
stylesheetfile | Specifies the CSS stylesheet to use | 1.2+ | No
charset | Charset for cross-platform viewing of generated documentation | 1.2+ | No
docencoding | Output file encoding name | all | No
doclet | Specifies the class file that starts the doclet used in generating the documentation. | 1.2+ | No
docletpath | Specifies the path to the doclet class file that is specified with the -doclet option. | 1.2+ | No
docletpathref | Specifies the path to the doclet class file that is specified with the -doclet option by reference to a PATH defined elsewhere. | 1.2+ | No
additionalparam | Lets you add additional parameters to the javadoc command line. Useful for doclets. Parameters containing spaces need to be quoted using &quot;. | all | No
failonerror | Stop the buildprocess if the command exits with a returncode other than 0. | all | No
excludepackagenames | comma separated list of packages you don't want docs for. | all | No
defaultexcludes | indicates whether default excludes should be used (`yes` | `no`); default excludes are used when omitted. | all | No
useexternalfile | indicates whether the sourcefile name specified in srcfiles or as nested source elements should be written to a temporary file to make the command line shorter. Also applies to the package names specified via the packagenames attribute or nested package elements. (`yes` | `no`). Default is no. | 1.2+ | No
source | Necessary to enable javadoc to handle assertions present in J2SE v 1.4 source code. Set this to "1.4" to documents code that compiles using `"javac -source 1.4"`. | 1.4 | No

#### Format of the group attribute

The arguments are comma-delimited. Each single argument is 2 space-delimited strings, where the first one is the group's title and the second one a colon delimited list of packages.

If you need to specify more than one group, or a group whose title contains a comma or a space character, using nested group elements is highly recommended.

E.g.,

        group="XSLT_Packages org.apache.xalan.xslt*,XPath_Packages org.apache.xalan.xpath*"

### Parameters specified as nested elements

#### packageset

A DirSet. All matched directories that contain Java source files will be passed to javadoc as package names. Package names are created from the directory names by translating the directory separator into dots. Ant assumes the base directory of the packageset points to the root of a package hierarchy.

The `packagenames`, `excludepackagenames` and `defaultexcludes` attributes of the task have no effect on the nested `<packageset>` elements.

#### fileset

A FileSet. All matched files will be passed to javadoc as source files. Ant will automatically add the include pattern `**/*.java` to these filesets.

Nested filesets can be used to document sources that are in the default package or if you want to exclude certain files from documentation. If you want to document all source files and don't use the default package, packagesets should be used instead as this increases javadocs performance.

The `packagenames`, `excludepackagenames` and `defaultexcludes` attributes of the task have no effect on the nested `<fileset>` elements.

#### package

Same as one entry in the list given by `packagenames`.

##### Parameters

Attribute | Description | Required
name | The package name (may be a wildcard) | Yes

#### excludepackage

Same as one entry in the list given by `excludepackagenames`.

##### Parameters

Same as for `package`.

#### source

Same as one entry in the list given by `sourcefiles`.

##### Parameters

Attribute | Description | Required
file | The source file to document | Yes

#### doctitle

Same as the `doctitle` attribute, but you can nest text inside the element this way.

#### header

Similar to `<doctitle>`.

#### footer

Similar to `<doctitle>`.

#### bottom

Similar to `<doctitle>`.

#### link

Create link to javadoc output at the given URL. This performs the same role as the link and linkoffline attributes. You can use either syntax (or both at once), but with the nested elements you can easily specify multiple occurrences of the arguments.

##### Parameters

Attribute | Description | Required
href | The URL for the external documentation you wish to link to | Yes
offline | True if this link is not available online at the time of generating the documentation | No
packagelistLoc | The location to the directory containing the package-list file for the external documentation | Only if the offline attribute is true

#### group

Separates packages on the overview page into whatever groups you specify, one group per table. This performs the same role as the group attribute. You can use either syntax (or both at once), but with the nested elements you can easily specify multiple occurrences of the arguments.

##### Parameters

Attribute | Description | Required
title | Title of the group | Yes, unless nested `<title>` given
packages | List of packages to include in that group. Multiple packages are separated with ':'. | Yes, unless nested `<package>`s given

The title may be specified as a nested `<title>` element with text contents, and the packages may be listed with nested `<package>` elements as for the main task.

#### doclet

The doclet nested element is used to specify the doclet that javadoc will use to process the input source files. A number of the standard javadoc arguments are actually arguments of the standard doclet. If these are specified in the javadoc task's attributes, they will be passed to the doclet specified in the `<doclet>` nested element. Such attributes should only be specified, therefore, if they can be interpreted by the doclet in use.

If the doclet requires additional parameters, these can be specified with `<param>` elements within the `<doclet>` element. These paramaters are restricted to simple strings. An example usage of the doclet element is shown below:

      <javadoc ... >
         <doclet name="theDoclet"
                 path="path/to/theDoclet">
            <param name="-foo" value="foovalue"/>
            <param name="-bar" value="barvalue"/>
         </doclet>
      </javadoc>

#### tag

The tag nested element is used to specify custom tags. This option is only available with Java 1.4.

##### Parameters

Attribute | Description | Required
name | Name of the tag (e.g. `todo`) | Yes
description | Description for tag (e.g. `To do:`) | Yes
enabled | Whether or not the tag is enabled (defaults to `true`) | No
scope | Scope for the tag - the elements in which it can be used. This is a comma separated list of some of the elements: `overview`, `packages`, `types`, `constructors`, `methods`, `fields` or the default, `all`. | No

#### taglet

The taglet nested element is used to specify custom taglets. This option is only available with Java 1.4.

##### Parameters

Attribute | Description | Required
name | The name of the taglet class (e.g. `com.sun.tools.doclets.ToDoTaglet`) | Yes
path | A path specifying the search path for the taglet class (e.g. `/home/taglets`). The path may also be specified by a nested <path> element | No

#### sourcepath, classpath and bootclasspath

`Javadoc`'s sourcepath, classpath and bootclasspath attributes are PATH like structure and can also be set via nested sourcepath, classpath and bootclasspath elements respectively.

### Example

      <javadoc packagenames="com.dummy.test.*"
               sourcepath="src"
               excludepackagenames="com.dummy.test.doc-files.*"
               defaultexcludes="yes"
               destdir="docs/api"
               author="true"
               version="true"
               use="true"
               windowtitle="Test API">
        <doctitle><![CDATA[<h1>Test</h1>]]></doctitle>
        <bottom><![CDATA[<i>Copyright &#169; 2000 Dummy Corp. All Rights Reserved.</i>]]></bottom>
        <tag name="todo" scope="all" description="To do:" />
        <group title="Group 1 Packages" packages="com.dummy.test.a*"/>
        <group title="Group 2 Packages" packages="com.dummy.test.b*:com.dummy.test.c*"/>
        <link offline="true" href="http://java.sun.com/products/jdk/1.2/docs/api/" packagelistLoc="C:\tmp"/>
        <link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
      </javadoc>

is the same as

      <javadoc
               destdir="docs/api"
               author="true"
               version="true"
               use="true"
               windowtitle="Test API">

        <packageset dir="src" defaultexcludes="yes">
          <include name="com/dummy/test/**" />
          <exclude name="com/dummy/test/doc-files/**"/>
        </packageset>

        <doctitle><![CDATA[<h1>Test</h1>]]></doctitle>
        <bottom><![CDATA[<i>Copyright &#169; 2000 Dummy Corp. All Rights Reserved.</i>]]></bottom>
        <tag name="todo" scope="all" description="To do:" />
        <group title="Group 1 Packages" packages="com.dummy.test.a*"/>
        <group title="Group 2 Packages" packages="com.dummy.test.b*:com.dummy.test.c*"/>
        <link offline="true" href="http://java.sun.com/products/jdk/1.2/docs/api/" packagelistLoc="C:\tmp"/>
        <link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
      </javadoc>

or

      <javadoc
               destdir="docs/api"
               author="true"
               version="true"
               use="true"
               windowtitle="Test API">

        <fileset dir="src" defaultexcludes="yes">
          <include name="com/dummy/test/**" />
          <exclude name="com/dummy/test/doc-files/**"/>
        </fileset>

        <doctitle><![CDATA[<h1>Test</h1>]]></doctitle>
        <bottom><![CDATA[<i>Copyright &#169; 2000 Dummy Corp. All Rights Reserved.</i>]]></bottom>
        <tag name="todo" scope="all" description="To do:" />
        <group title="Group 1 Packages" packages="com.dummy.test.a*"/>
        <group title="Group 2 Packages" packages="com.dummy.test.b*:com.dummy.test.c*"/>
        <link offline="true" href="http://java.sun.com/products/jdk/1.2/docs/api/" packagelistLoc="C:\tmp"/>
        <link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
      </javadoc>

Copyright © 2000-2002 Apache Software Foundation. All rights Reserved.