Generating Javadoc with Ant

     

You can also generate your Javadoc using the Ant utility. Ant is available as a free download from http://ant.apache.org. The current version, as of this publication, is 1.6.1. Ant is used like the make tool to automate the software build process. It offers an XML syntax featuring tags that, among other things, wrap common Java tools, including the javadoc command.

While in this section it is not appropriate to go into the Ant tool in detail, my assumption here is that this will serve as a useful ”if quick ”reference later when you want to generate Javadoc using Ant.

If you are using Eclipse (3.0 is the current version), you already have Ant installed with it. All you need to do is create a file (conventionally called build.xml), and add it to your project. You can then add Ant tags to that file, and then execute the script using the built-in Ant plugin.

Writing the Build Script

Here is a sample script that you can use in your projects to easily generate your Javadoc.

 

 build.xml <?xml version="1.0" encoding="UTF-8"?> <project name="My Project Build" default="init"> <property name="src.dir" value="code/source"/> <property name="docs.dir" value="./docs"/>     <!Create documentation. >     <target name="Generate JavaDoc" depends="">         <javadoc packagenames="myrootpackage.*"              sourcepath="${src.dir}"              destdir="${docs.dir}/javadoc"               access="private"               windowtitle="My Window Title"               verbose="true"               author="true"               version="true">              <bottom>                  <![CDATA[<b>Java Garage, Eben                     Hewitt, 2004<b>]]>               </bottom>           </javadoc>      </target> </project> 

This script will pick up all of the Javadoc tags you have written down to the "private" level. If you specify access="public" , then only Javadoc comments on public methods will be written out to the Javadoc.

The text between the "bottom" tags is optional and represents some arbitrary text that you can place at the bottom of every page. It is appropriate for copyright.

When this script is executed, it creates all of the Javadoc for you, and places the files in the docs/javadoc directory ”the value of the destdir attribute.

For extensive , helpful documentation on using the Ant tool to automate your builds, check out http://ant.apache.org/manual/.

Executing the Ant Script in Eclipse

While you don't need Eclipse to execute Ant scripts, Ant is often used as a plugin to an IDE, and comes built-in with Eclipse, and is the simplest way to demonstrate without going into detail here. Note that you need to have a directory structure that matches the one you specify in your build.xml file for the Javadoc destination.

Once you have the script modified to your liking, here is how to run it:

  1. In the Eclipse IDE, choose Window from the main menu, and click Show View > Ant.

  2. Click the three yellow plus sings to add the build.xml file to your project.

  3. Once you have done so, click the green forward arrow in the Ant window to execute the script. The console window will open and show you the verbose output that Ant generates as it executes the script.

Ant is explored in more detail in the More Java Garage book.

That's it! Happy Javadoc-ing.



Java Garage
Java Garage
ISBN: 0321246233
EAN: 2147483647
Year: 2006
Pages: 228
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net