This article describes how you can automatically draw a UML diagram from your Java source code.
NetBeans UML (Click to enlarge...)
If you need to solve this problem and your IDE is Eclipse, you likely landed here by searching for keywords like "java to uml eclipse". When I did the same, I learned that there's nothing good available that is both free and easy. There is UML2 Tools for eclipse, but it only allows you to draw diagrams manually. It does not allow you to automatically generate diagrams from source code. There may be a way, but not without installing additional plugins and going through a laborious process. In other words, if there is a way, it is not easy. There are some other plugins available, but they are either half-baked, not compatible with your version of Eclipse, or they do not support round-tripping. Of course, there are also commercial tools available, but they cost a fortune.
If you need something good, free, and easy - here's your ticket: use NetBeans.
Don't worry, you do not have to use NetBeans as your day-to-day IDE - you only need to use it to solve this one problem. Here's how:
- Download NetBeans from here
(I chose the "All" bundle; version 6.7.1). - Install and run the NetBeans IDE
- In NetBeans, select Tools > Plugins
- In the list of Available Plugins, select UML and click Install (accept Terms, etc., etc.)
- Now you need to import your Eclipse project. Don't worry, you can just make the project visible to NetBeans while leaving it in-place and in-tact in your Eclipse workspace directory. Choose File > Import Project > Eclipse Project...
- Make sure the "Import Projects from Workspace" option is selected and then "Browse..." to locate your Eclipse workspace. Click Next.
- Now select the Eclipse project from which you want to generate UML and click Finish. The project will become visible in NetBeans. Don't worry if you have compiler errors in NetBeans that you did not have in Eclipse. For the purposes of generating UML from your classes, we do not need to reconfigure the project in NetBeans so that it compiles properly.
- Select File > New Project...
- In the Choose Project dialog, select the Category "UML" and the project "Reverse Engineered Java-Platform Model" and click Next.
- For Java Project, choose the Eclipse project that you imported into NetBeans, check any source folders that you might want to use in your diagramming, and click Finish.
- Now you have your Eclipse project and a new UML project in NetBeans. Almost there!
- Right click on the Diagrams node under your UML project and choose New > Diagram...
- Choose Class Diagram for the type and click Finish. An empty class diagram is created.
- You cannot drag and drop class files from your imported Eclipse project onto the canvas. Instead, expand the Model node of the UML project and you should find your classes there.
- Drag and drop classes from the UML project onto the diagramming canvas.
It is not the perfect round-tripping solution, but it works, it's pretty simple, and it's free. Just be aware that if you delete your imported Eclipse project from NetBeans, DO NOT select "Also Delete Sources Under..." or you'll lose your Eclipse master.
Add Comment