Note: The code samples discussed in this post are available at http://www.github.com/bradleyross/tutorials while the documentation can be found at http://bradleyross.github.io/tutorials. This project uses Maven. Although you don’t have to use Maven, the comments in the pom.xml and other configuration files provide a great deal of useful information.

Introduction

As I mentioned in a previous post1, documentation is required in order to understand and debug the code. The Javadoc tool from Oracle provides a means of documenting Java code with the software development software itself carrying out the bulk of the effort.2 Meanwhile, the Maven pom.xml file provides a mean of providing additional information about the project in a computer readable manner.

  • By processing the source code, it can generate a document that lists all of the classes in a project, including descriptions of the methods, fields, and constructors. Since it generates this information from the source code, it will always be up to date.
  • It provides a method for the programmer to insert additional information into the document by reading specially formatted comments in the code.
  • The Javadoc can contain the complete source code, with links from the detailed descriptions of the fields, constructors, and methods taking the user to their location in the source code.
  • It is possible to link the Javadocs for libraries used by the project to the Javadocs for the project itself. This can make it
    much easier to review the code.
  • Using Maven and Javadocs together allow you to get a great deal of useful documentation for little effort. When the Agile Manifesto4 states Working software over comprehensive documentation, this is because of the Law of Diminishing Returns5. Spending too much time on documentation is wasteful, but not documenting at all will cause major problems later.

Like other Maven plugins, the Javadoc plugin has a number of conventions concerning where the files should be placed.6 These conventions will be discussed in terms of the tutorials example.

Example

The bradleyross/tutorials project on GitHub is a package that I wrote to provide some examples for various lessons and tutorials.7. Documentation for the code can also be found in GitHub.8.

  • Each Maven module should be located in it’s own directory on the server containing the documentation, and the Javadoc should be contained in the subdirectory apidocs for that directory. The main directory for the module is then placed in the pom.xml file using the tag url. For the tutorials-common module, the URL for the module documentation is http://bradleyross.github.io/tutorials/tutorials-common/ while the URL for the Javadocs is http://bradleyross.github.io/tutorials/tutorials-common/apidocs/.
  • The modifications to the pom.xml file can be placed in either the module for which the Javadocs are being generated or in the parent module. I placed them in the parent module for simplicity.
  • The overview for the module goes in the file src/main/javadoc/overview.html.

References

Advertisements