Generating UML From the NetBeans IDE

by John Zukowski

Imagine having been given the source code for a project that needs to be maintained, and the maintainer is long gone. You have the task of adding a new feature. Take a look at what you can discover by using a tool such as the Unified Modeling Language (UML) Modeling module of the NetBeans IDE 5.5 to explore the source code and generate UML diagrams of the system.

The file , which includes a project designed by Sun Microsystems. It is a basic address-book management system. Using the NetBeans IDE and the UML Modeling module, you'll discover the objects in this application.

First, you need to install the NetBeans IDE, if you don't have it already.

Launch the NetBeans IDE. By default, the UML Modeling Module is not part of the installation, so you must add that after installing and launching the IDE. Go to the Update Center's Tools menu, then click on Update Center to launch the wizard:

Make sure you have selected the NetBeans Update Center option. When you select Next, the wizard connects to each Update Center for potential modules to add, such as the UML Modeling one. Although you can also install the UML Bank App Sample module, it is the UML Modeling module under Features that you need to install for this article.

Although the UML Modeling module is only 10 KB, pressing Add with UML Modeling selected will add not only the selected module but all of its dependencies, totaling over 18 MB in this case.

Press the Next button at the bottom to add all the necessary modules and get the UML Modeling module, after you accept a few licensing agreements.

After the 17 modules, including UML Modeling, are installed, press the Next button to see the list of certificates you must view before installation, and then press Finish. This will prompt you to restart the IDE to install the modules.

You'll see the IDE exit and restart while it installs everything. Once it has restarted, you can now start analyzing the provided source.

To open this project, select the File menu, then the Open Project menu item. You'll need to locate the top-level directory for where you unzipped the ZIP file. For instance, if you unzipped everything to C:\\work, select the ABook entry in the C:\\work directory, then press the Open Project Folder button. Loading causes a complaint about the derby JAR file not being found. Just click past the problem for now. You're not going to run anything just yet.

Now that you have a project, it is time to reverse engineer it and generate some UML. To do that, you will create a second project. Select File, then New Project. Select UML from the Categories on the left, then select Reverse Engineer a Java Project from the Projects on the right.

Pressing the Next button brings up the new Reverse Engineer a Java Project window. Make sure ABook is the Java Project and press the Finish button. Change the default location if you wish the new project to be nearer the source code.

At this point, the source from the ABook project has been imported, but no diagrams have been generated. You have to manually select the elements you wish to generate diagrams for. Looking quickly through the class names, Contact looks like the primary data-related class. Right-clicking on the class in the Projects window will allow you to select Create Diagram From Selected Elements.

You then pick the type of diagram to generate, Class Diagram, and press the Finish button.

You'll then have the generated diagram in a new window on your desktop. Feel free to increase the percentage to see the diagram better. It is a little small because class has many properties and operations. You can copy the diagram to the clipboard to paste it into OpenOffice or just view it to learn about the class design.

Without generating any diagrams, you can see the attributes, operations, and relationships of a class. For instance, if you open the Relationships of the ContactEditor, you'll see it has several Aggregation associations. You'll also notice it is a generalization of a JFrame, and an implementation of an ActionListener and ListSelectionListener. The generalization reveals the parent class. The implementations reveal the implemented interfaces.

To get into some more interesting diagrams, right-click on ContactList and Generate Dependency Diagram to show what that class depends on. The diagram is small because it depends on quite a few other things. Increase the percentage to see things a little better. You'll find ContactList on the bottom, with dependencies on ContactDataModel, ContactEditor, and several other classes. The Dependency Diagram includes the Class Diagram for each class involved.

Generating a sequence diagram is easy from the dependency diagram. Just right-click on one of the Operations and select Reverse Engineer Operation.

This brings up the Create New Diagram window with a different set of available diagrams to generate. From here, you can get a Sequence or Collaboration Diagram. Select Sequence Diagram and press the Finish button.

For the newContactActionPerformed operation, you then get the following diagram.

That's the whole process of reverse engineering your Java source code. Try out the module to generate some of the other supported UML diagrams. The process is basically the same, just select a different diagram type from the Create New Diagram window.


After installing the NetBeans IDE and project, I tried to Open Project, but nothing happens. I am not presented with another window to select the project to be opened. Dead in the water.

Posted by Doug Thomas on June 27, 2007 at 02:44 AM PDT #

Hi, This information was extremely useful. Thank you very much.

Posted by James on June 27, 2007 at 11:44 AM PDT #


Posted by hassan on July 03, 2007 at 08:37 PM PDT #


Posted by guest on July 27, 2007 at 04:10 PM PDT #

Thank you for writing this excellent article - please keep them coming! Netbeans is a great piece of work.

Posted by James on July 27, 2007 at 07:23 PM PDT #

Excellent guide.. thanks a lot

Posted by Aneesh Varghese on August 07, 2007 at 01:33 PM PDT #

Thank you for writing this GREAT article - please keep UPDATE ME . coming! Netbeans is a great piece of work.

Posted by VIVEK KUMAR KANAUJIA on August 17, 2007 at 07:11 PM PDT #

thanks but if i dont have network connection then how do i install updates??

Posted by sumit on August 18, 2007 at 02:54 PM PDT #

Thanks for this great tutorial.

It was exactly what I was looking for...

Posted by Fernando Pereira on August 29, 2007 at 04:26 AM PDT #

It's a very nice information to know about java

Posted by abhishek on November 06, 2007 at 01:24 PM PST #


Posted by guest on December 10, 2007 at 08:43 PM PST #

Thank you! Really appreciate it.

Posted by Sabry on December 23, 2007 at 03:27 PM PST #


Posted by jjm on January 18, 2008 at 05:51 AM PST #

great tutorial! very helpful!

Posted by rbielun on January 22, 2008 at 12:24 AM PST #

Hello. I´m spanish and I don´t know english very well, so sorry. I have a question. I want to get the proyect UML from the example addressbook from XIndice, but Ican´t. If someone could help me I thank you.

Posted by Fernando on April 25, 2008 at 03:34 AM PDT #

really great...

Posted by Shyam on July 14, 2008 at 09:49 PM PDT #

It was what i was looking forward for .Such small but focussed information becomes more useful than many books while we were looking for such short precise support.Thanks a lot .

Posted by Vinay Shrivastava on August 09, 2008 at 01:02 PM PDT #


Posted by guest on September 06, 2008 at 07:33 AM PDT #

Awesome. thanks alot guys

Posted by Piet on September 20, 2008 at 02:33 AM PDT #

This is all very nice, but the generated UML is way too detailed. Is there no way I can configure what comes out of the reenginering UML-diagram-generation?
I need a simple class-diagram showing only the name of the class, the names of the attributes, the names of the operations, and the connections to my other classes!
The whole point of UML-modeling is to simplify communication towards non-developers! they don't need to know about public/private access, and all parameters of every operation!

Posted by Superole on October 12, 2008 at 05:37 PM PDT #

Thanks a lot for this great tutorial

It was very close what I was looking for

Posted by Poonkodi R on January 15, 2009 at 05:35 PM PST #

I'm working on a similar tool right now - it's called jTracert and can build sequence diagrams automatically.

You can take a look at it here:

Unlike NetBeans it doesn't parse existing code. Instead it is implemented as a javaagent and analyzes existing Java applications in runtime.

Posted by Dmitry Bedrin on February 18, 2009 at 06:23 PM PST #

Post a Comment:
Comments are closed for this entry.

Java Technology Fundamentals are now covered as part of the Core Java Technology Tech Tips. Please go there for more tech tips.


« July 2016