Now that we have the ability to test our code, next will need the ability to generate documentation for our project. Ant has a builtin javadoc task that is perfect for this and we can integrate this into our build procedure. As the project grows in complexity, these documents will become more and more useful.
<!-- ==========================================================
javadoc
Generate a java document based on source code comments
========================================================== -->
<target name="javadoc" description="api generation">
<echo level="info">
***********************************************************************
*
* Generating documentation
*
***********************************************************************
</echo>
<property name="dir.build.docs.api" value="${dir.build.docs}/api"/>
<property name="doc.title" value="Java Persistence Project"/>
<property name="doc.copyright" value="Copyright © 2009 Travis Osterman. All Rights Reserved."/>
<delete dir="${dir.build.docs.api}"/>
<mkdir dir="${dir.build.docs}"/>
<mkdir dir="${dir.build.docs.api}"/>
<javadoc
destdir="${dir.build.docs.api}"
author="true"
version="true"
use="true"
windowtitle="${doc.title}"
failonerror="true"
classpathref="classpath"
>
<fileset dir="${dir.src}" defaultexcludes="yes">
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</fileset>
<!-- custom html -->
<doctitle><![CDATA[<h1>${doc.title}</h1>]]></doctitle>
<bottom><![CDATA[<i>${doc.copyright}</i>]]></bottom>
<!-- custom tags -->
<tag name="todo"
description="<span class="todo">todo</span>" />
<tag name="xxx"
description="<span class="xxx">needs refactored</span>" />
<tag name="fixme"
description="<span class="fixme">needs fixed</span>" />
<tag name="TODO"
description="<span class="todo">todo</span>" />
<tag name="XXX"
description="<span class="xxx">needs refactored</span>" />
<tag name="FIXME"
description="<span class="fixme">needs fixed</span>" />
<!-- link to other api's -->
<!-- java api -->
<link href="http://java.sun.com/j2se/1.5/docs/api"/>
</javadoc>
</target>
javadoc
Generate a java document based on source code comments
========================================================== -->
<target name="javadoc" description="api generation">
<echo level="info">
***********************************************************************
*
* Generating documentation
*
***********************************************************************
</echo>
<property name="dir.build.docs.api" value="${dir.build.docs}/api"/>
<property name="doc.title" value="Java Persistence Project"/>
<property name="doc.copyright" value="Copyright © 2009 Travis Osterman. All Rights Reserved."/>
<delete dir="${dir.build.docs.api}"/>
<mkdir dir="${dir.build.docs}"/>
<mkdir dir="${dir.build.docs.api}"/>
<javadoc
destdir="${dir.build.docs.api}"
author="true"
version="true"
use="true"
windowtitle="${doc.title}"
failonerror="true"
classpathref="classpath"
>
<fileset dir="${dir.src}" defaultexcludes="yes">
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</fileset>
<!-- custom html -->
<doctitle><![CDATA[<h1>${doc.title}</h1>]]></doctitle>
<bottom><![CDATA[<i>${doc.copyright}</i>]]></bottom>
<!-- custom tags -->
<tag name="todo"
description="<span class="todo">todo</span>" />
<tag name="xxx"
description="<span class="xxx">needs refactored</span>" />
<tag name="fixme"
description="<span class="fixme">needs fixed</span>" />
<tag name="TODO"
description="<span class="todo">todo</span>" />
<tag name="XXX"
description="<span class="xxx">needs refactored</span>" />
<tag name="FIXME"
description="<span class="fixme">needs fixed</span>" />
<!-- link to other api's -->
<!-- java api -->
<link href="http://java.sun.com/j2se/1.5/docs/api"/>
</javadoc>
</target>
And now add comments using /** comment */ and try
> ant javadoc
Now access JP\build\docs\api
> ant svn
commit
Javadoc