Geertjan is a DZone Zone Leader and has posted 468 posts at DZone. You can read more from them at their website. View Full User Profile

Generate UML Diagrams into Javadoc in NetBeans Projects

  • submit to reddit

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.*"
            <path path="${javac.classpath}"/>
        <fileset dir="${src.dir}" excludes="${excludes}"
            <filename name="**/*.java"/>
        <doclet name="org.umlgraph.doclet.UmlGraphDoc"
            <param name="-attributes" />
            <param name="-operations" />
            <param name="-qualify" />
            <param name="-types" />
            <param name="-visibility" />

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 file, but there's nothing you need to do yourself, since all properties in the target above reuse the predefined targets in the 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:

fig-1.png66.26 KB
fig-2.png46.37 KB
Published at DZone with permission of its author, Geertjan Wielenga.


Meera Subbarao replied on Wed, 2008/08/27 - 7:13am

Nice article, Geertjan. I sure will try this.

Geertjan Wielenga replied on Wed, 2008/08/27 - 7:58am

Well, it's all thanks to you, Meera!

Varun Nischal replied on Wed, 2008/08/27 - 8:20am

Amazing :)

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"> 



Kt Parikh replied on Wed, 2010/02/17 - 7:32am

Please help me with this: I am also getting the error No source files and no packages have been specified at the last line(private=true). It is not able to find the source packages. I am not able to understand why this is happening, as this is working with another project of similar structure, but throwing this error for other projects. I have added the jar file and cross checked almost everything. Please help with this. Thanks and Regards, KT

Kt Parikh replied on Wed, 2010/02/17 - 7:33am in response to: IRA RA

did u get the reason why this was happening? I am facibng the same problem. Please help.

Javier Ortiz replied on Mon, 2010/06/21 - 3:15pm

Any reason for this not working now? UmlGraph-5.3 For some reason it complains about not finding dot:

Building Package view for package games.jwrestling.common Cannot run program "dot": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start( at java.lang.Runtime.exec( at java.lang.Runtime.exec( at org.umlgraph.doclet.UmlGraphDoc.runGraphviz( at org.umlgraph.doclet.UmlGraphDoc.generatePackageDiagrams( at org.umlgraph.doclet.UmlGraphDoc.start( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at at at at at at 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

mexican dip recipes   have encountered error too.

Carla Brian replied on Sun, 2012/07/08 - 5:51pm

This is really amazing. I didn't know about this one. Good thing I saw your post. This  is really an helpful tool for everyone. - Mercy Ministries

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 Park

Bryan 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

DUO Residences is also near to Bugis Junction as well as the buzzling city area. Entertainment for your loved ones and friends is therefore at your fingertips with the full condo facilities as well as the amenities in Bugis. DUO Residences

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

Several buses are available near Lush Acres EC along with shopping centers and restaurants. Lush Acres EC is also near Waterway Point, the shopping, dining and entertainment hub which is scheduled to open in 2 years time. Also, it is right beside Punggol Waterfront. Entertainment for your loved ones and friends are therefore at your fingertips with the full condo facilities as well as the amenities near Lush Acres EC. Sengkang West Way EC

Bryan Low replied on Mon, 2013/06/24 - 1:35am

Several buses are available near Forestville EC along with shopping centers and restaurants. Forestville EC is also near Causeway Point as well as Woodlands Waterfront. Entertainment for your loved ones and friends are therefore at your fingertips with the full condo facilities as well as the amenities near Forestville EC. Forestville EC will be accessible with Woodlands MRT station & Admiralty MRT station. It is also near to Vista Point Shopping Mall, Causeway Point Shopping Mall, Cold Storage, Shop N Save, and many more. Forestville EC Location

Bryan Low replied on Tue, 2013/07/09 - 1:36am

Sembawang EC is also near elite schools such as Singapore American School, Wellington Primary School, Canberra Primary School and Endeavour Primary School. It is also near to Singapore Sports School and Innova Junior College. Sembawang EC

Bryan Low replied on Fri, 2013/07/12 - 4:25am

Sea Horizon EC will be accessible via Pasir Ris MRT Station. Commuting to Changi Airport as well as Expo is therefore very convenient. It is also near to White Sands and Pasir Park. Sea Horizon Register Interest

Bryan Low replied on Sat, 2013/07/13 - 6:49am

Commuting to Tampines as well as the city area is therefore very convenient. The Glades is also near to Changi Airport as well as Changi International Business Park. The Glades is also near elite schools such as Anglican High School, St. Anthony’s Canossian Primary & Secondary School and Temasek Junior College. Tampines Junior College, Temasek Polytechnic and United World College (East Campus) is also around in the area. The Glades

John Tan replied on Sat, 2013/08/03 - 5:22am

 Waterwoods is an executive condominium expected to be ready in Punggol in 2016. It features 6 blocks, each 18 storeys of luxurious EC units and is jointly developed by Sing Holdings Limited & UE E&C Limited. Waterwoods

John Tan replied on Sat, 2013/08/03 - 5:24am

 SkyPark Residences is the latest EC to be launched in Sembawang.  The land parcel is located at the junction of Sembawang Drive and Sembawang Avenue.  This location is close to Sembawang MRT and bus interchange.  SkyPark Residences is sitting on a good-sized land surrounded by excellent ammenities. skypark residences

Comment viewing options

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