Class Diagram Operations

To use UMLGraph class drawing facility you need to have javadoc and Graphviz installed on your computer. Both programs are freely available, from Sun and AT&T respectively, for many platforms including Unix and Windows. UMLGraph's input follows the Java syntax and semantics. However, since the main purpose of UMLGraph is the declarative specification of UML diagrams there is no need to flesh-out each class's methods, to completely specify each class, or to specify package information. You only specify the details you want to appear on the graph. If you wish your (Java) implementation to evolve together with the design feel free to include code or additional details. You can hide these details from the UML diagram using the javadoc @hidden tag applied to classes, methods, and fields. In theory you can also use UMLGraph to reverse engineer existing Java code. Note however that UMLGraph was not originally designed for this purpose; the resulting graphs may be large and unwieldy.

UMLGraph is implemented as a javadoc doclet (a program satisfying the doclet API that specifies the content and format of the output generated by the javadoc tool). Javadoc is part of the Sun JDK, so a typical JDK installation will also include javadoc. Before running javadoc you need to place the UmlGraph.jar file in a directory that also contains the Java SDK tools.jar file. You can accomplish this either by copying UmlGraph.jar to the SDK lib directory where tools.jar resides, or by copying the JDK tools.jar file into the directory where you install UmlGraph. You then run

java -jar /path/to/UmlGraph.jar yourfile1.java ...
You can use any of the javadoc general options; -private is usually needed to avoid having to explicitly specify public elements. Example:
java -jar /usr/jvm/java-1.5.0/lib/UmlGraph.jar -private Simple.java

Specifying some packages before the list of source files will designate those packages as local. When you specify a package list, the SVG output UmlGraph generates will contain local hyperlinks for the local classes and hyperlinks to the Sun Java API documentation for all other classes.

javadoc will create by default a file named graph.dot in the current directory. This is a text file that can be processed by the Graphviz dot program to layout and draw the graph. A command line like the following will convert the graph.dot file into Postscript:

dot -Tps -ograph.ps graph.dot
or PNG
dot -Tpng -ograph.png graph.dot
Refer to the dot documentation for information on creating other file formats or adjusting the UMLGraph output.

You also can pipe the result of UMLGraph directly into dot:

java -jar /.../UmlGraph.jar -private -output - Simple.java | dot -Tgif -ograph.gif
In the bin directory of the UMLGraph distribution you will find a Unix shell script and a Microsoft Windows batch file that you can customize to invoke UmlGraph and dot through a single command.

Alternatively, you can also run UMLGraph from within javadoc. This can be useful if your IDE provides additional support for running javadoc. In this case you run javadoc with arguments -doclet gr.spinellis.umlgraph.doclet.UmlGraph -docletpath /path/to/UmlGraph.jar and append at the end the file(s) that contain your diagram specification. Example:

javadoc -docletpath UmlGraph.jar -doclet gr.spinellis.umlgraph.doclet.UmlGraph -private Simple.java

Note that when you use dot for generating SVG diagrams your should specify the -outputencoding UTF-8 option to UMLGraph. This option will correctly render the stereotype guillemot characters in the dot output and the corresponding SVG file.