Documenting Code
Creating applications in a commercial environment
frequently means creating documentation, and Ant is up for that with the
javadoc task. This task creates
documentation using the Java javadoc
tool, a process that involves compilation, which merits including this
task in this chapter. This is one of the largest tasks in Ant because of
the enormous number of javadoc
options.
Here's an example, stored in the javadoc folder in the code for this book. Suppose you add a documentation-type comment to the Project.java file:
/** This application prints out "No worries." */
public class Project
{
public static void main(String args[])
{
System.out.println("No worries.");
}
}You can create Javadoc for the project using the javadoc task in a new target I'll name
doc, which will put the generated
Javadoc in a doc directory, as you see in Example 3-3.
Tip
Note the XML <![CDATA[...]> sections, which the
build file uses to pass data to the javadoc tool.
Example 3-3. Creating javadoc (ch03/javadoc/build.xml)
<?xml version="1.0" ?> <project default="main"> <property name="message" value="Building the .jar file." /> <property name="src" location="source" /> <property name="docs" location="docs" /> <property name="output" location="bin" /> <target name="main" depends="init, compile, doc, compress"> <echo> ${message} </echo> </target> <target name="init"> <mkdir dir="${output}" /> <mkdir dir="${docs}" /> </target> <target name="compile"> <javac srcdir="${src}" destdir="${output}" /> </target> ...