Ant Javadoc的简单应用

 

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}"
			failοnerrοr="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

AttributeDescriptionAvailabilityRequired
sourcepathSpecify where to find source filesallAt least one of the three or nested<sourcepath>,<fileset> or<packageset>
sourcepathrefSpecify where to find source files by reference to a PATH defined elsewhere.all
sourcefilesComma separated list of source files -- see also the nested sourceelement.all
destdirDestination directory for output filesallYes, unless a doclet has been specified.
maxmemoryMax amount of memory to allocate to the javadoc VMallNo
packagenamesComma separated list of package files (with terminating wildcard) -- see also the nested package element.allNo
packageListThe name of a file containing the packages to processallNo
classpathSpecify where to find user class filesallNo
BootclasspathOverride location of class files loaded by the bootstrap class loaderallNo
classpathrefSpecify where to find user class files by reference to a PATH defined elsewhere.allNo
bootclasspathrefOverride location of class files loaded by the bootstrap class loader byreference to a PATH defined elsewhere.allNo
ExtdirsOverride location of installed extensionsallNo
OverviewRead overview documentation from HTML fileallNo
accessAccess mode: one of publicprotectedpackage, or private allNo (defaultprotected)
PublicShow only public classes and membersallNo
ProtectedShow protected/public classes and members (default)allNo
PackageShow package/protected/public classes and membersallNo
PrivateShow all classes and membersallNo
OldGenerate 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.2No
VerboseOutput messages about what Javadoc is doingallNo
LocaleLocale to be used, e.g. en_US or en_US_WINallNo
EncodingSource file encoding nameallNo
VersionInclude @version paragraphsallNo
UseCreate class and package usage pagesallNo
AuthorInclude @author paragraphsallNo
SplitindexSplit index into one file per letterallNo
WindowtitleBrowser window title for the documentation (text)allNo
DoctitleInclude title for the package index(first) page (html-code)allNo
HeaderInclude header text for each page (html-code)allNo
FooterInclude footer text for each page (html-code)allNo
bottomInclude bottom text for each page (html-code)allNo
linkCreate links to javadoc output at the given URL -- see also the nested linkelement.allNo
linkofflineLink to docs at <url> using package list at <url2> - separate the URLs by using a space character -- see also the nested link element.allNo
groupGroup specified packages together in overview page. The format is as described below -- see also the nested group element.allNo
nodeprecatedDo not include @deprecated informationallNo
nodeprecatedlistDo not generate deprecated listallNo
notreeDo not generate class hierarchyallNo
noindexDo not generate indexallNo
nohelpDo not generate help linkallNo
nonavbarDo not generate navigation barallNo
serialwarnGenerate warning about @serial tagallNo
helpfileSpecifies the HTML help file to useallNo
stylesheetfileSpecifies the CSS stylesheet to useallNo
charsetCharset for cross-platform viewing of generated documentationallNo
docencodingOutput file encoding nameallNo
docletSpecifies the class file that starts the doclet used in generating the documentation -- see also the nested doclet element.allNo
docletpathSpecifies the path to the doclet class file that is specified with the -doclet option.allNo
docletpathrefSpecifies the path to the doclet class file that is specified with the -doclet option by reference to a PATH defined elsewhere.allNo
additionalparamLets 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.allNo
failonerrorStop the buildprocess if the command exits with a returncode other than 0.allNo
excludepackagenamescomma separated list of packages you don't want docs for -- see also the nested excludepackage element.allNo
defaultexcludesindicates whether default excludes should be used (yes | no); default excludes are used when omitted.allNo
useexternalfileindicates 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.allNo
sourceNecessary 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
linksourceGenerate hyperlinks to source files. since Ant 1.6. (yes | no). Default is no.1.4+No
breakiteratorUse the new breakiterator algorithm. since Ant 1.6. (yes | no). Default is no.1.4+No
noqualifierEnables the -noqualifier argument - must be all or a colon separated list of packages. since Ant 1.6.1.4+No
includenosourcepackagesIf set to true, packages that don't contain Java source but a package.html will get documented as well. since Ant 1.6.3.allNo (default isfalse)
executableSpecify 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.allNo
docfilessubdirsEnables deep-copying of doc-files subdirectories. Defaults to false. since Ant 1.8.0.1.4No
excludedocfilessubdirColon-separated list of doc-files' subdirectories to exclude ifdocfilessubdirs is true. since Ant 1.8.0.1.4No
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 packagenamesexcludepackagenames 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 (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
AttributeDescriptionRequired
nameThe 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
AttributeDescriptionRequired
fileThe source file to documentYes
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
AttributeDescriptionRequired
hrefThe URL for the external documentation you wish to link to. This can be an absolute URL, or a relative file name.Yes
offlineTrue if this link is not available online at the time of generating the documentationNo
packagelistLocThe location to the directory containing the package-list file for the external documentationOne of the two if the offline attribute is true
packagelistURLThe URL of the the directory containing the package-list file for the external documentation
resolveLinkIf 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
AttributeDescriptionRequired
titleTitle of the groupYes, unless nested <title>given
packagesList 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
AttributeDescriptionRequired
nameName of the tag (e.g. todo)Yes, unless the dirattribute is specified.
descriptionDescription for tag (e.g. To do:)No, the javadoc executable will pick a default if this is not specified.
enabledWhether or not the tag is enabled (defaults to true)No
scopeScope 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
dirIf 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
AttributeDescriptionRequired
nameThe name of the taglet class (e.g. com.sun.tools.doclets.ToDoTaglet)Yes
pathA path specifying the search path for the taglet class (e.g. /home/taglets). The path may also be specified by a nested <path> elementNo
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 arguments. Since 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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值