`

Ant Javadoc的简单应用

    博客分类:
  • Ant
 
阅读更多

 

Javadoc的简单例子:

<?xml version="1.0" encoding="UTF-8"?>
<project name="ant" default="javadoc">

	<property name="from.dir" location="src"/>
	<property name="to.dir" location="javadoc"/>
	<property name="project.name" location="测试项目"/>

	<property name="dir.lib" location="WebContent/WEB-INF/lib"/>
  
    <path id="javadoc.classpath">  
        <fileset dir="${dir.lib}">  
            <include name="commons-lang-2.4.jar"/>
        </fileset>  
    </path>

	<target name="javadoc" depends="clean">
		<javadoc
			sourcepath="${from.dir}"
			destdir="${to.dir}"
			packagenames="diary.*"
			use="true"
			version="true"
			windowtitle="${project.name}"
			failonerror="true">
			<classpath refid="javadoc.classpath"/>
		</javadoc>
	</target>

	<target name="clean">
		<mkdir dir="${to.dir}"/>
		<delete>
			<fileset dir="${to.dir}">
				<include name="**/*"/>
			</fileset>
		</delete>
	</target>
</project>

 

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 javactask. This means all packages will be processed each time this task is run. In general, however, this task is used much less frequently.

NOTE: since javadoc calls System.exit(), javadoc cannot be run inside the same VM as Apache 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.2 means available if your current Java VM is a 1.2 VM (but not 1.3 or later), 1.4+ for any VM of at least version 1.4, otherwise any VM of at least version 1.2 is acceptable. JDKs <1.4 are no longer supported. If you specify the executableattribute it is up to you to ensure that this command supports the attributes you wish to use.

Note:
When generating the JavaDocs for classes which contains annotations you maybe get a java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl. This is due bug-6442982. The cause is that JavaDoc cannot find the implementations of used annotations. The workaround is providing the jars with these implementations (like JAXBs @XmlType, ...) to <javadoc> usingclasspathclasspathref attributes or nested <classpath> element.

Note: many problems with running javadoc stem from command lines that have become too long - even though the error message doesn't give the slightest hint this may be the problem. If you encounter problems with the task, try to set the useexternalfileattribute to true first.

If you use multiple ways to specify where javadoc should be looking for sources your result will be the union of all specified documentations. If you, e.g., specify a sourcepath attribute and also a nested packageset both pointing at the same directory your excludepackagenames attribute won't have any effect unless it agrees with the exclude patterns of the packageset (and vice versa).

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 -- see also the nested sourceelement. 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) -- see also the nested package element. all No
packageList The name of a file containing the packages to process all No
classpath Specify where to find user class files all No
Bootclasspath Override location of class files loaded by the bootstrap class loader all 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 byreference to a PATH defined elsewhere. all No
Extdirs Override location of installed extensions all No
Overview Read overview documentation from HTML file all No
access Access mode: one of publicprotectedpackage, or private all No (defaultprotected)
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.
Note: as of Ant 1.8.0 this attribute doesn't have any effect since the javadoc of Java 1.4 (required by Ant 1.8.0) doesn't support the -1.1 switch anymore.
1.2 No
Verbose Output messages about what Javadoc is doing all No
Locale Locale to be used, e.g. en_US or en_US_WIN all No
Encoding Source file encoding name all No
Version Include @version paragraphs all No
Use Create class and package usage pages all No
Author Include @author paragraphs all No
Splitindex Split index into one file per letter all No
Windowtitle Browser window title for the documentation (text) all No
Doctitle Include title for the package index(first) page (html-code) all No
Header Include header text for each page (html-code) all No
Footer Include footer text for each page (html-code) all No
bottom Include bottom text for each page (html-code) all No
link Create links to javadoc output at the given URL -- see also the nested linkelement. all No
linkoffline Link to docs at <url> using package list at <url2> - separate the URLs by using a space character -- see also the nested link element. all No
group Group specified packages together in overview page. The format is as described below -- see also the nested group element. all No
nodeprecated Do not include @deprecated information all No
nodeprecatedlist Do not generate deprecated list all No
notree Do not generate class hierarchy all No
noindex Do not generate index all No
nohelp Do not generate help link all No
nonavbar Do not generate navigation bar all No
serialwarn Generate warning about @serial tag all No
helpfile Specifies the HTML help file to use all No
stylesheetfile Specifies the CSS stylesheet to use all No
charset Charset for cross-platform viewing of generated documentation all No
docencoding Output file encoding name all No
doclet Specifies the class file that starts the doclet used in generating the documentation -- see also the nested doclet element. all No
docletpath Specifies the path to the doclet class file that is specified with the -doclet option. all No
docletpathref Specifies the path to the doclet class file that is specified with the -doclet option by reference to a PATH defined elsewhere. all No
additionalparam Lets you add additional parameters to the javadoc command line. Useful for doclets. Parameters containing spaces need to be quoted using &quot; -- see also the nested arg element. 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 -- see also the nested excludepackage element. 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. Since Ant 1.7.0, also applies to all the other command line options. (yes | no). Default is no. all 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".
A default value for this attribute can be provided using the magicant.build.javac.source property.
1.4+ No
linksource Generate hyperlinks to source files. since Ant 1.6. (yes | no). Default is no. 1.4+ No
breakiterator Use the new breakiterator algorithm. since Ant 1.6. (yes | no). Default is no. 1.4+ No
noqualifier Enables the -noqualifier argument - must be all or a colon separated list of packages. since Ant 1.6. 1.4+ No
includenosourcepackages If set to true, packages that don't contain Java source but a package.html will get documented as well. since Ant 1.6.3. all No (default isfalse)
executable Specify a particular javadoc executable to use in place of the default binary (found in the same JDK as Ant is running in). since Ant 1.6.3. all No
docfilessubdirs Enables deep-copying of doc-files subdirectories. Defaults to false. since Ant 1.8.0. 1.4 No
excludedocfilessubdir Colon-separated list of doc-files' subdirectories to exclude ifdocfilessubdirs is true. since Ant 1.8.0. 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

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 packagenamesexcludepackagenames and defaultexcludes attributes of the task have no effect on the nested <packageset>elements.

fileset

FileSet. All matched files will be passed to javadoc as source files. Ant will automatically add the include pattern **/*.java (and**/package.html if includenosourcepackages is true) 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 packagenamesexcludepackagenames and defaultexcludes attributes of the task have no effect on the nested <fileset>elements.

sourcefiles

A container for arbitrary file system based resource collections. All files contained in any of the nested collections (this includes nested filesets, filelists or paths) will be passed to javadoc as source files.

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.

If the nested text contains line breaks, you must use the useexternalfile attribute and set it to true.

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. This can be an absolute URL, or a relative file name. 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 One of the two if the offline attribute is true
packagelistURL The URL of the the directory containing the package-list file for the external documentation
resolveLink If the link attribute is a relative file name, Ant will first try to locate the file relative to the current project's basedir and if it finds a file there use an absolute URL for the link attribute, otherwise it will pass the file name verbatim to the javadoc command. No, default is false.

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 parameters 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

If you want to specify a standard tag using a nested tag element because you want to determine the order the tags are output, you must not set the description attribute for those tags.

Parameters
Attribute Description Required
name Name of the tag (e.g. todo) Yes, unless the dirattribute is specified.
description Description for tag (e.g. To do:) No, the javadoc executable will pick a default if this is not specified.
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: overviewpackagestypes,constructorsmethodsfields or the default, all. No
dir If this attribute is specified, this element will behave as an implicit fileset. The files included by this fileset should contain each tag definition on a separate line, as described in the Javadoc reference guide:
ejb.bean:t:XDoclet EJB Tag
todo:a:To Do
Note: The Javadoc reference quide has double quotes around the description part of the definition. This will not work when used in a file, as the definition is quoted again when given to the javadoc program. 
Note: If this attribute is specified, all the other attributes in this element will be ignored.
No

taglet

The taglet nested element is used to specify custom taglets.

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 sourcepathclasspath and bootclasspath attributes are PATH like structure and can also be set via nested sourcepath,classpath and bootclasspath elements respectively.

arg

Use nested <arg> to specify additional arguments. See Command line argumentsSince Ant 1.6

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://download.oracle.com/javase/6/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://download.oracle.com/javase/6/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://download.oracle.com/javase/6/docs/api/" packagelistLoc="C:\tmp"/>
    <link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
  </javadoc>
分享到:
评论

相关推荐

    如何用ant生成javadoc

    Apache Ant是一款开源的Java构建工具,它通过XML文件定义构建过程,可以用来编译、调试、测试和部署Java应用程序。Ant提供了丰富的内置任务(task),支持多种任务的组合和定制,非常适合大型项目的自动化构建需求。 ...

    对于ANT的概述

    - **跨平台性**:ANT是纯Java编写的应用,因此可以在任何支持Java的平台上运行。 - **操作简单**:ANT的操作基于XML配置文件,易于理解和维护。 - **高度可定制**:通过扩展自定义任务,可以实现丰富的构建逻辑。...

    apache-ant-1.9.16-bin.zip

    使用Apache Ant,开发者可以定义一系列的任务,每个任务可以是简单的文件操作,也可以是复杂的构建流程,如编译Java代码、生成Javadoc、创建JAR文件、执行单元测试等。Ant通过XML语法来描述这些任务,使得构建过程...

    ant学习笔记之(ant执行命令的详细参数和Ant自带的系统属性)

    Ant,作为一个基于Java的构建工具,因其跨平台性以及XML格式的构建脚本而被广泛应用于自动化构建过程,如编译、打包、测试等。本篇文章将深入探讨Ant执行命令的详细参数以及Ant自带的系统属性,帮助开发者更好地理解...

    ant简单介绍

    安装Ant相当简单,通常只需要将Ant的bin目录添加到系统的PATH环境变量中。例如,在Linux系统中,可以编辑`/etc/profile`,添加ANT_HOME和JAVA_HOME的路径,并更新PATH,确保能直接运行`ant`命令。安装完成后,Ant...

    apache-ant-1.9.3-src.tar

    虽然ANT可调用的外部应用种类非常丰富,但其实最常用的就2,3个:比如javac javadoc jar等。 Ant的优点 Ant是Apache软件基金会JAKARTA目录中的一个子项目,它有以下的优点。 跨平台性。Ant是纯Java语言编写的,所...

    java的Ant打包工具

    5. **简洁的命令行接口**:Ant可以通过简单的命令行参数启动,方便进行持续集成和脚本化操作。 在实际使用中,一个典型的Ant构建文件(`build.xml`)会包含多个目标,例如: ```xml ...

    ant学习指南 ANT是一个基于Java的自动化脚本引擎

    通过分析这些实际应用的脚本,我们可以了解如何配置任务、设定属性、调用外部工具(如javac、javadoc和jar),以及如何处理文件和目录操作。例如,以下是一个简单的Ant构建脚本片段: ```xml &lt;!-- 初始化目标 --&gt;...

    Ant教程 doc文件

    Ant的构建文件采用了简洁明了的陈述式语法,这意味着开发者可以通过简单的XML标签和属性来描述构建过程,无需编写复杂的脚本或命令。这种语法设计大大降低了学习曲线,使新用户也能快速上手。 ##### 3. 工程与目标 ...

    ant打包工具

    在大型项目中,Ant通常与Maven或Gradle一起使用,负责特定的构建任务,如生成Javadoc、清理旧构建产物等。通过合理配置,Ant可以很好地集成到持续集成(CI)流程中,确保项目构建的一致性和可重复性。 总结,Ant作为...

    apache-ant安装包

    Ant的核心理念是“简单的事物应该简单,复杂的事物应该可能”,这使得它成为了一个灵活且强大的构建系统。 Apache Ant 1.9.4 是该工具的一个版本,发布于2015年,包含了Ant的基本功能和一些改进。在这一版本中,你...

    Java Development with Ant

    - **第一个构建脚本**:通过一个简单的示例介绍如何编写第一个Ant构建脚本,包括设置项目名称、定义目标等基本操作。 - **常用任务**:介绍一些常用的Ant任务,如`javac`用于编译Java源文件,`jar`用于创建JAR文件等...

    Java的Build工具—Ant应用指南(1)

    这篇“Java的Build工具—Ant应用指南(1)”将引领我们走进Ant的世界,了解其基本概念、配置和使用方法。 1. Ant基本概念 - 构建文件:Ant的主要工作是通过读取一个名为`build.xml`的XML文件来执行构建任务。这个...

    apache-ant-1.9.7.rar

    总的来说,Apache Ant是Java项目管理和自动化构建的强大工具,它简化了开发流程,提高了工作效率,尤其在大型项目中,其可配置性和可扩展性得到了广泛应用。对于初学者来说,理解Ant的工作原理和XML配置语法是快速...

    apache-ant-1.7.1

    Apache Ant 是一个开源的构建工具,主要用于Java项目,但也可以应用于其他语言的构建过程。它以其XML为基础的构建文件和可扩展的任务集而闻名,使得自动化编译、打包、测试和部署等工作变得简单且可重复。`apache-...

    自动化打包工具 ant-1.9.1组件包大集合

    这个文件定义了一系列的任务(tasks),这些任务涵盖了编译源代码、运行测试、打包应用程序、创建Javadoc等开发过程中的关键步骤。Ant 通过任务(Tasks)和目标(Targets)来组织构建逻辑,任务是执行特定操作的单元...

    java Ant入门教程

    随着 Java 技术的发展和应用越来越广泛,Ant 也逐渐成为了 Java 项目构建的标准之一。 #### 二、Ant 的功能与优势 Ant 的主要功能包括但不限于: 1. **跨平台支持**:由于 Ant 是用 Java 编写的,因此它可以轻松...

    Ant教程-详细使用方法

    下面通过一个简单的构建文件示例来解释 Ant 的基本结构: ```xml &lt;javadoc destdir="build/classes" sourcepath="src" packagenames="org.*"/&gt; ,doc"&gt; ``` - **工程**: `...

Global site tag (gtag.js) - Google Analytics