It is very useful to have UML Diagrams integrated into your javadoc – they give you a neat visual overview of the contents of you sourcecode. I want to show you how to integrate this into an automated build. I implemented this with an ant target and my IDE Netbeans.
Add this to your build.xml in the root of your project:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <?xml version="1.0" encoding="UTF-8"?> <!-- You may freely edit this file. See commented blocks below for --> <!-- some examples of how to customize the build. --> <!-- (If you delete it and reopen the project it will be recreated.) --> <!-- By default, only the Clean and Build commands use this build script. --> <!-- Commands such as Run, Debug, and Test only use this build script if --> <!-- the Compile on Save feature is turned off for the project. --> <!-- You can turn off the Compile on Save (or Deploy on Save) setting --> <!-- in the project's Project Properties dialog box.--> <project name="Aufgabe2" default="default" basedir="."> <description>Builds, tests, and runs the project Aufgabe2.</description> <property file="nbproject/project.properties"/> <import file="nbproject/build-impl.xml"/> <target name="javadocs" depends="-post-compile" description="generates javadoc and also UML Diagram"> <echo message="Generating Javadoc and UML Diagram to: ${dist.javadoc.dir}"/> <mkdir dir="${dist.javadoc.dir}"/> <javadoc sourcepath="${src.dir}" packagenames="com.bla.*" destdir="${dist.javadoc.dir}" private="true"> <doclet name="org.umlgraph.doclet.UmlGraphDoc" path="lib/UmlGraph.jar"> <param name="-windowtitle" /> <param name="-attributes" /> <param name="-operations" /> <param name="-qualify" /> <param name="-types" /> <param name="-visibility" /> <param name="-inferdep" /> <param name="-inferrel" /> <param name="-all" /> </doclet> </javadoc> <apply executable="dot" dest="${dist.javadoc.dir}" parallel="false"> <arg value="-Tpng"/> <arg value="-o"/> <targetfile/> <srcfile/> <fileset dir="${dist.javadoc.dir}" includes="*.dot"/> <mapper type="glob" from="*.dot" to="*.png"/> </apply> <nbbrowse file="${dist.javadoc.dir}/index.html"/> </target> </project> |
You will need Graphviz and UMLGraph.
I had to execute sudo ln -s /usr/local/bin/dot /usr/bin/dot on my Mac OSX to make dot work. Since it was not recognized in my PATH and quitted with the error:
Cannot run program "dot": error=2, No such file or directory ensure that dot is in your path and that its path does not contain spaces
Arguments
You can pass several arguments to UML Grap. You can find a full list on the website.
Generate
You can start build like this:
If everything works fine you will see:
The javadoc is opened in your browser.
Shortcut
For convenience you can add a shortcut to build your javadoc and UML diagrams.