Wednesday, April 23, 2008

Javadoc Comments and Eclipse

Javadoc allows developers to automatically generate documentation for their code. All you need to do to use Javadoc is include comments before your functions that fit the javadoc format. Then you can use Eclipse to automatically generate the documentation for your project's code. The output has a list of classes and descriptions of parameters, returns, methods, etc. Here's how.

Comment Format

Put comments in the following format before functions:

/** Your comments go here (the javadoc gets wacky if you put them elsewhere)
@param [comma delimited list of params here, case must match!]
@return [non-void type]
*/

Note the use of /** instead of the usual /* to start the comment.

If you want a line break in the generated html, you must use a br tag.

Eclipse

Now to generate the javadoc, click on the root level of your project in the Project Explorer, go to Eclipse's Project menu and choose Generate Javadoc

Eclipse will require a "javadoc command." Actually, this is just the path to javadoc. Javadoc is in the bin directory of the sdk install of java. So just paste in the path to javadoc.exe and you are good to go. Hit finish and you'll have documentation dumped into a /doc folder in your project.

A step by step tutorial is available here.

No comments:

Labels

Blog Archive

Contributors