Skip to main content

Enhance your javadoc with ULMGraph

Posted by survivant on December 26, 2009 at 3:38 PM PST

We can't live without Javadoc, but even if it useful, it's not complete. One missing thing is UML within the Javadoc.

To add UML to your Javadoc, is quite simple. You need to add Graphviz into your maven build.

First you need to download and install Graphviz. Go there Graphviz

After that you should add the variable GRAPHVIZ_HOME (that point to the installation folder) into your system.

The last step is to add the plugin into your pom.

Add the lines in bold.

[prettify]
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <version>2.6.1</version>
  <configuration>
    <links>
      <link>http://java.sun.com/javase/6/docs/api/</link>
    </links>
    <detectOfflineLinks />
    <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
    <!--
      use this line or use the variable GRAPHVIZ_HOME
      <docletPath>/path/to/UmlGraph.jar</docletPath>
    -->
    <docletArtifact>
      <groupId>org.umlgraph</groupId>
      <artifactId>doclet</artifactId>
      <version>5.1</version>
    </docletArtifact>

    <additionalparam>-operations</additionalparam>
    <additionalparam>-qualify</additionalparam>
    <additionalparam>-types</additionalparam>
    <additionalparam>-visibility</additionalparam>
    <additionalparam>-collpackages</additionalparam>
    <show>private</show>
  </configuration>
</plugin> 
[/prettify]

With that you will have nice UML into your javadoc. I hope that help.

Comments

An alternative without installing Graphviz locally

             &lt;plugin&gt;
                &lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                            &lt;show&gt;package&lt;/show&gt;
                            &lt;version&gt;true&lt;/version&gt;
                            &lt;javadocVersion&gt;${source.version}&lt;/javadocVersion&gt;
                            &lt;links&gt;
                                &lt;link&gt;http://java.sun.com/javase/6/docs/api/&lt;/link&gt;
                                &lt;link&gt;http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/&lt;/link&gt;
                                &lt;link&gt;http://joda-time.sourceforge.net/api-release/&lt;/link&gt;
                                &lt;link&gt;http://findbugs.sourceforge.net/api/&lt;/link&gt;
                                &lt;link&gt;http://tomcat.apache.org/tomcat-6.0-doc/api/&lt;/link&gt;
                                &lt;link&gt;http://jetty.mortbay.org/jetty/jetty-6/apidocs/&lt;/link&gt;
                                &lt;link&gt;http://download.eclipse.org/jetty/stable-7/apidocs/&lt;/link&gt;
                                &lt;link&gt;https://grizzly.dev.java.net/nonav/apidocs/&lt;/link&gt;
                            &lt;/links&gt;          &lt;source&gt;1.6&lt;/source&gt;
                   &lt;code&gt;javadoc:aggregate&lt;/code&gt;
                    &lt;code&gt;javadoc:test-aggregate&lt;/code&gt;
                  &lt;doclet&gt;gr.spinellis.umlgraph.doclet.UmlGraphDoc&lt;/doclet&gt;
                  &lt;docletArtifact&gt;
                    &lt;groupId&gt;gr.spinellis&lt;/groupId&gt;
                    &lt;artifactId&gt;UmlGraph&lt;/artifactId&gt;
                    &lt;version&gt;4.6&lt;/version&gt;
                  &lt;/docletArtifact&gt;
                  &lt;additionalparam&gt;
                    -inferrel -inferdep -quiet -hide java.*
                    -collpackages java.util.* -qualify
                    -postfixpackage -nodefontsize 9
                    -nodefontpackagesize 7
                  &lt;/additionalparam&gt;
                &lt;/configuration&gt;
              &lt;/plugin&gt;

It will use Graphviz, but it will download it from the web instead of forcing the local installation.. :)

thanks.

thanks.

I tried it before but it didn't work for unknown reason.  I'll switch to your way.  I prefer that.

 

 

How to use Graphviz on non-Maven projects ?

Hi I'd like to have UML on my Javadocs, but had no plans to use Maven. Any ideas ?

Never try and didn't look for

Never try and didn't look for that.  I know there are plugin to ant to launch maven task.  Maybe you can use that.

Fantastic!

This immediately went onto my project. Thanks for the tip, both of you.