Agile Zone is brought to you in partnership with:

Meera has posted 70 posts at DZone. You can read more from them at their website. View Full User Profile

Javadoc or Doxygen?

09.10.2008
| 31919 views |
  • submit to reddit

In the last two articles, "Reverse-engineer Source Code into UML Diagrams" and "Visual Documentation of Ant Dependencies in 3 Simple Steps"  we saw how easy and valuable it was to automate technical documentation. By using open source tools, we were easily able to provide good technical documentation within a few minutes, and at no cost at all. We were also able to keep this up-to date by adding additional tasks to our Ant build files, and run them from our CI Server(Hudson in our case) on commit and nightly builds, and also publish the results.

In this article, I will be showing you how to use yet another tool called Doxygen for generating technical documentation based on your source code. We all have used Javadoc and have been using it for a long time, right? So, you may ask what's the need to have another tool which produces the same HTML documentation? Doxygen has a slight edge over Javadoc and here are a few reasons why you should consider using the same:

  1. With Javadoc you have to remember all the HTML tags, you need to embed within your code comments. However, with Doxygen code comments are much more concise and polished, without the need for any HTML.

  2. Doxygen can also generate a variety of diagrams, we will take a look at some of them later.

  3. Doxygen also provides a structured view on the source code. As I mentioned in 2 above in the form of various diagrams, cross-referenced and syntax highlighted code.

  4. You get all the above benefits even if the code does not have any comments at all. 

  5. Last but not the least, Doxygen is a documentation system not for just Java but also for various other languages like  C++, C, Java, Objective-C, Python, IDL (Corba and Microsoft flavors), Fortran, VHDL, PHP, C#.


So, without wasting further time, lets see what we need to get started with Doxygen.

Step 1. Download, Install Doxygen.

Download the binary distribution for Doxygen for the operating system you are using. I downloaded the binary distribution for Mac OS X called Doxygen-1.5.6.dmg. Installation is very simple, just drag the doxygen icon from this folder to the Applications folder, or wherever you want to keep it; as shown. I dropped it within my Applications folder. Just be sure to remember where you dragged it. To uninstall, just delete the file. It is completely self-contained.  

 

Step 2: Configure Doxygen. 

To generate documentation using Doxygen, you will need a configuration file called the Doxyfile. You can generate this file in two ways; either by using the Doxygen wizard or by using the command line option. Lets see how to use both these options to generate the configuration file:

a. Command line. Open a command window and type the following as shown below:

You should be able to locate the configuration file created within your default user folder. The file looks like this:

# Doxyfile 1.5.6

# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project
#
# All text after a hash (#) is considered a comment and will be ignored
# The format is:
#       TAG = value [value, ...]
# For lists items can also be appended using:
#       TAG += value [value, ...]
# Values that contain spaces should be placed between quotes (" ")

#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------

# This tag specifies the encoding used for all characters in the config file
# that follow. The default is UTF-8 which is also the encoding used for all
# text before the first occurrence of this tag. Doxygen uses libiconv (or the
# iconv built into libc) for the transcoding. See
# http://www.gnu.org/software/libiconv for the list of possible encodings.

DOXYFILE_ENCODING      = UTF-8

# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.

PROJECT_NAME           =

# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
# if some version control system is used.

PROJECT_NUMBER         = 

 

b. Wizard Option.

Launch the  Doxygen application, and you should be able to create the configuration file using the wizard approach as shown below.

 

The user interface is quite intuitive so I am going to skip explaining this in detail.
The wizard approach was the one I used to get the initial settings for the configuration file. which you can always modify later.

A few options in my Doxygen configuration file are as follows:

# Doxyfile 1.5.6

#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING      = UTF-8
PROJECT_NAME           = PetStore
PROJECT_NUMBER         = 1.0
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL            = NO
EXTRACT_PRIVATE        = NO
EXTRACT_STATIC         = NO
EXTRACT_LOCAL_CLASSES  = YES
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML          = YES
HTML_OUTPUT            = html
HTML_FILE_EXTENSION    = .html
GENERATE_TREEVIEW      = YES

Published at DZone with permission of its author, Meera Subbarao.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Gian Franco Casula replied on Wed, 2008/09/10 - 10:07am

Hi Meera,

Thanks for your article, I always enjoy reading them...

I think javadoc is doing a good job and although Doxygen looks fine I wouldn't necessarily want to migrate to it.

It took some serious effort to convince people to document their code in javadoc in the first place.

Gian

Meera Subbarao replied on Wed, 2008/09/10 - 10:18am in response to: Gian Franco Casula

[quote=gianfranco]

Thanks,Gian. I appreciate your comments. If you had to convince your developers to document their code in Javadoc, than you definitely need Doxygen. They have to hardly remember any HTML tags at all. 

[/quote] Meera Subbarao

Collin Fagan replied on Wed, 2008/09/10 - 4:36pm

If I remember correctly Doxygen supports Javadoc style comments. I've seen people run Doxygen over the JDK sources and come out with advanced documentation. It's a great tool even if you want to stay javadoc compatible.

Meera Subbarao replied on Wed, 2008/09/10 - 5:14pm in response to: Collin Fagan

Yes indeed. If you already have Javadoc comments, you need nothing else.

Meera Subbarao

David Sills replied on Thu, 2008/09/11 - 5:58am

Obviously, I'm going to have to try Doxygen. This looks great! Thanks, Meera!

Meera Subbarao replied on Thu, 2008/09/11 - 7:05am in response to: David Sills

[quote=davidsills]Obviously, I'm going to have to try Doxygen. [/quote]

 Thanks, David. Give it a try and you will be surprised how easy it is to keep the technical documentation up-to date.

Meera Subbarao

Meera Subbarao replied on Thu, 2008/09/11 - 7:16am in response to: rouletteroulette rouletteroulette

[quote=pdrummond]

I blogged about this ages ago:

http://gushieblog.blogspot.com/2006/06/doxygen-versus-javadoc.html

[/quote]

Thanks for sharing the link, Paul. Interesting article.

Meera Subbarao

Philippe Lhoste replied on Fri, 2008/09/12 - 4:43am

I discovered Doxygen some years ago, and found it was a very valuable tool. I was so disappointed to see, later, that JavaDoc was so limited!

One advantage you don't seem to mention is that being HTML agnostic, it allows to output documentation in various formats like RTF, PDF or CHM.
One thing I like too is flexibility: you can use line comments as well as block comments, and even more, you don't have to put all documentation in the header of a method: you can document a function parameter directly where it is defined, Doxygen will extract the names from the code. I have seen way too often JavaDoc headers missing half of parameters (added later in the code) or referencing wrong variable names, either because they have changed or because of copy/paste of a header of another function, forgetting to update it!

PS: You have a typo: Dxoygen. :)

Meera Subbarao replied on Fri, 2008/09/12 - 5:48am in response to: Philippe Lhoste

[quote=philho]

One advantage you don't seem to mention is that being HTML agnostic, it allows to output documentation in various formats like RTF, PDF or CHM.

PS: You have a typo: Dxoygen. :)

[/quote]

Yes, I am not sure how I missed writing about other formats. Thanks for sharing.

Corrected the one and only typo.

Meera Subbarao

Richard Kowalsky replied on Mon, 2008/09/29 - 7:58am

Thanks for the excellent article.  Tips like these go a long ways towards helping some of

us do a much more thorough job with our software development.  Keep up the good work!

;-)

Mal Malper replied on Sat, 2008/11/29 - 9:26am

I am using a std. header we have set in our software division to work for C++ code and also for other documentation preperation.

We have a significant amount of Java code too. Since our priority is Docygen , recently I was trying to port written java code documentation to Doxygen.

However  I could  not prepare the html doxygen outputs correctly with the Java class headers we had. So I modified one or two headers, like the way we have done for C++ so that we would use one doc tool for both java and C++.  Now the java headeer works well work for Doxygen.

We have some guys who prefer Javadocs. So I was trying to use Javadocs with the new Java header I created (that works with Doxygen). But now I cannot produce the proper Javadoc html with that header.

So it seems that 100% javadoc working header comments does not work 100% with Doxygen and vise versa.

I cannot change the C++ std header style we use as that is our standard.

But I am trying hard to get this headers working in Javadocs.

Willing to post a sample header if someone here has any ideas.

 

Thanks

MP

 

john green green replied on Fri, 2009/10/23 - 2:07am

We have some guys who prefer Javadocs. So I was trying to use Javadocs with the newnike shoes new Java header I created (that works with Doxygen). But now I cannot produce the proper Javadoc html with that header.

john green green replied on Sun, 2009/10/25 - 8:50am

I've seen people run Doxygen over the JDK nike shoes chinasources and come out with advanced documentation. It's a great tool even if you want to stay javadoc compatible.

Jose Marquez replied on Wed, 2010/02/17 - 2:00am

There is a plug in to integrate Doxygen to Eclipse named eclox . I havent tried it, Just found out about it. I will let you know how my experience goes with the plug-in. Developement was discontinued on december 2009, so, it might be just a short term solution until someone decides to take on this project again. link: http://home.gna.org/eclox/

Bhaskar Rao replied on Wed, 2011/01/19 - 11:30pm

Hi Meera,

Thanks for your article, really it is very helpful to understand Doxygen. Currently we are planning to switch to Doxygen from Javadoc for technical documentation.
Our project is on Windows platform using Java, we are using ant script for build purpose. I am very new to ant script and not able to find much help on "How to configure and use the Doxygen tool using ant script on Windows platform.
I need your help on this. Please... help me.

Regards,
Bhaskar

Carla Brian replied on Fri, 2012/06/22 - 8:33pm

I think this is an effective application. I will definitely download this one. I will study more on this.-  CWD Construction

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.