Generate UML Diagrams into Javadoc in NetBeans Projects
One incredibly useful article recently on Javalobby is called Reverse-engineer Source Code into UML Diagrams, by Meera Subbarao. Sandip wrote a similar article, on the same GraphViz functionality, in one of his last Sun blogs, Trunk NetBeans cluster dependency graph generated using dot. The latter is particularly interesting for NetBeans Platform users, since (if you get everything working right) you should be able to generate dependency graphs between modules in your NetBeans Platform application. But, let's leave that for another article.
Here I simply want to outline what I needed to do to apply Meera's instructions to a standard NetBeans Java project. First of all, here is the target you need to put into "build.xml". Take note of the fact that the target is called "-post-compile", which means that it will be run automatically whenever a build is completed. Therefore, you'll not need to do anything other than invoke the project's build command and then you'll end up with UML diagrams in your Javadoc. So here's the target:
<target name="-post-compile" description="Generates UML-Javadoc">
<mkdir dir="${dist.javadoc.dir}"/>
<javadoc source="${javac.source}" packagenames="com.*"
destdir="${dist.javadoc.dir}"
private="true">
<classpath>
<path path="${javac.classpath}"/>
</classpath>
<fileset dir="${src.dir}" excludes="${excludes}"
includes="${includes}">
<filename name="**/*.java"/>
</fileset>
<doclet name="org.umlgraph.doclet.UmlGraphDoc"
path="${file.reference.UmlGraph.jar}">
<param name="-attributes" />
<param name="-operations" />
<param name="-qualify" />
<param name="-types" />
<param name="-visibility" />
</doclet>
</javadoc>
</target>
OK, now some other comments on the target above. Firstly, it is based on the standard NetBeans Javadoc target, supplemented with some extra tags from Meera's article. Note especially the following:
- Line 2: "dist.javadoc.dir" and all other properties, are all set in the project.properties file, but there's nothing you need to do yourself, since all properties in the target above reuse the predefined targets in the project.properties file.
- Line 3: The "packagenames" attribute sets the package names to be included, so here I've set everything from "com" onwards (e.g., "com.pkg.subpkg.etc" to be included).
- Line 14: The "file.reference.UmlGraph.jar" property is generated when you add the UmlGraph.jar (created according to Meera's article) to the application's Libraries node. You could change this to something different, that's up to you, so long as it points to UmlGraph.jar
And that's all I needed. I'm on Ubuntu, so all I needed to do was this to get the dot program to work:
sudo apt-get install graphviz
That's all. Then build the project and you'll find DOT files and PNG files added to the "dist" folder:
Open one of the HTML files and there you'll see magically your UML diagrams:

| Attachment | Size |
|---|---|
| fig-1.png | 66.26 KB |
| fig-2.png | 46.37 KB |





Comments
Meera Subbarao replied on Wed, 2008/08/27 - 7:13am
Geertjan Wielenga replied on Wed, 2008/08/27 - 7:58am
Varun Nischal replied on Wed, 2008/08/27 - 8:20am
IRA RA replied on Thu, 2009/05/28 - 1:31pm
I have this error no source file and no package have been specified Line:
<javadoc source="${javac.source}" packagenames="com.*"
destdir="${dist.javadoc.dir}" private="true">Why?
Kt Parikh replied on Wed, 2010/02/17 - 7:32am
Kt Parikh replied on Wed, 2010/02/17 - 7:33am
in response to:
IRA RA
Javier Ortiz replied on Mon, 2010/06/21 - 3:15pm
Building Package view for package games.jwrestling.common java.io.IOException: Cannot run program "dot": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at java.lang.Runtime.exec(Runtime.java:593) at java.lang.Runtime.exec(Runtime.java:466) at org.umlgraph.doclet.UmlGraphDoc.runGraphviz(UmlGraphDoc.java:134) at org.umlgraph.doclet.UmlGraphDoc.generatePackageDiagrams(UmlGraphDoc.java:97) at org.umlgraph.doclet.UmlGraphDoc.start(UmlGraphDoc.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:269) at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:143) at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340) at com.sun.tools.javadoc.Start.begin(Start.java:128) at com.sun.tools.javadoc.Main.execute(Main.java:41) at com.sun.tools.javadoc.Main.main(Main.java:31) The weird thing is that dot is accessible from the command prompt. I tried restarting the IDE without luck. When is the Netbeans RCP version of this going to be available?
Matt Coleman replied on Tue, 2012/05/08 - 4:29am
in response to:
Javier Ortiz
is Netbeans RCP version out now?we would love to try it
graphic artist buffalo
Mateo Gomez replied on Wed, 2012/05/09 - 2:23am
Carla Brian replied on Sun, 2012/07/08 - 5:51pm
Bryan Low replied on Mon, 2012/12/24 - 10:58pm
Tanah Merah New Launch will be available via the Tanah Merah MRT Place (EW4) on the East-West Range. Watching Tampines as well as the town place is therefore very authentic.
It is also near to Changi Terminal as well as Changi Worldwide Company ParkBryan Low replied on Fri, 2013/02/01 - 10:11pm
Twin Fountains EC has full and unique facilities, which includes a guard house, clubhouse, Function Room & Indoor Gym Tennis Court, 50m Freeform Pool Pool Deck, Wading Pool, Splash Pool & Family Pool Jacuzzi & Hydro Spa, BBQ Area Dining and Play Fountain, Fitness Alcove & Children’s Playground and Garden Trail.
Twin Fountains Woodlands
Bryan Low replied on Sun, 2013/02/24 - 4:45am
Bartley Ridge has full and unique facilities, which includes a guard house, clubhouse, children’s playground, swimming pool, piano room, pool room, indoor gym, hydrotherapy beds, hydrotherapy baths, reading room, function room, onsen, jacuzzi.
Bryan Low replied on Thu, 2013/03/07 - 10:11pm
Hillview Peak is also near to Bukit Gombak Stadium and Bukit Batok Golf Range. Entertainment for your loved ones and friends is therefore at your fingertips with the full condo facilities as well as the amenities near Hillview Peak.
Hillview Condo
Eric Lim replied on Fri, 2013/03/15 - 9:05am
You have a very inspiring way of exploring and sharing your thoughts. It is very uncommon nowadays, lots of sites and blogs having copy pasted or rewritten info. Thx for the write-up.
New Launch | Urban Vista
Eric Lim replied on Fri, 2013/03/15 - 9:31am
Excellent information here, I'm assuming you meant this as a resource for all of us? I've bookmarked this so I can do just that.
New Launch | Sant RItz
Eric Lim replied on Fri, 2013/03/15 - 9:34am
Thank you for sharing with us such informative article. Hope to see more.
New Launch | Hillview Peak
Eric Lim replied on Fri, 2013/03/15 - 9:38am
This is a good article on how to generateGenerate UML Diagrams into Javadoc in NetBeans Project. Thanks for sharing.Bartley Ridge Condo | New Launch
Bryan Low replied on Mon, 2013/03/25 - 3:23am
Belgravia Villas is a new and upcoming cluster housing located in the Ang Mo Kio area, nested right in the Ang Mo Kio landed area. It is within a short drive to Little India, Orchard and city area. With expected completion in mid 2016, it comprises of 118 units in total with 100 units of terrace and 18 units of Semi-D.
Belgravia Villas Project Details
At Ppty replied on Sun, 2013/04/21 - 10:33pm
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.Corals at Keppel Bay
At Ppty replied on Mon, 2013/05/06 - 4:15am
The Trilinq ncludes of solely three towers of 36 storeys high, approximately 750 units which provides magnificent views towards Sungei Ulu Pandan and the Pandan Reservoir.The Trilinq Clementi provide an honest mixture of unit size ranges from 1, 2, 3, 4 bedroom and penthouses.
Bryan Low replied on Tue, 2013/06/04 - 12:59am
Andy Man replied on Wed, 2013/06/05 - 6:42am
Thomson View Condo is an upcoming project situated along Upper Thomson Road. It is located at a prime location just opposite Thomson Plaza Shopping Centre and is located within walking distance from the future Thomson MRT Station. Due to its easy accessibility, Thomson View Condo is definitely a great choice for investors and home-buyers.
Bryan Low replied on Mon, 2013/06/17 - 1:12am