Search code examples
javaumlclass-diagram

Automatic creation of complete class diagram from Java project


Is there a solution for automatic creation of a complete class diagram from a Java project?

I've spent significant time looking online, trying Papyrus, Jar2UML, UML2Tools, DiaGen, jGraps, Class-visualizer, but have not found any currently working solution. Although most of the mentioned tools work (some do not currently work), they do not automatically generate a diagram of the full class hierarchy. I realise this might be the holy grail, and may require parameterisation, but thought it should be possible this day.

Requirements for wider use would be:

  • Currently working
  • Easy to use, or up-to-date tutorial on exactly how to do this
  • Does not require manual coding
  • Stand alone or Eclipse/NetBeans/IntelliJ plugin
  • Free

If there is nothing like this available, I'm considering creating something like this.


Solution

  • Out of the fact I am not sure to have all the classes of a project into one class diagram is a good idea because the result is unreadable with lot of classes, you can do that for instance with my tool BoUML. After you download/install/run it :

    • create a new project
    • select Java in the global menu Languages
    • for the first directory dialog appearing press the button cancel (you do not have a java catalog) then for the second directory dialog select the root directory containing all the sources of Java you want to model, then wait for end
    • in the browser on the left in any of the created class view or in a new one you create yourself do a right mouse click and choose New class diagram and double click on it to open it
    • probably you need to hide details of classes in the diagram to limit its size (you can do that later but better to do that right now in case you have lot of classes), in that case do a right mouse click into the diagram or on it into the browser to edit the drawing settings and set to yes the settings hide classes attributes and hide classes operations then confirm (button ok)
    • use the button binocular on the top (near print button), change kind to class then use buttons search then mark them then close
    • into the open diagram (shown into the right part of the window) do a right mouse click and choose add marked elements placing classes in random position then redo a right mouse click and choose automatic layout (you can also move the classes by yourself of course)

    As you can see all the relations between classes are drawn, not only the generalization/realization. If you want only them without having for instance to hide all other relations one by one by hand you can develop a plug-out marking all the classes and generalization/realization of the model, then changing the procedure I given :

    • when you edit the drawing settings also go into the second tab and set to no the setting draw all relations
    • rather than to use the browser search (binocular button) to select all he classes use your plug-out

    Anyway, again, to show all the classes into one diagram is a bad idea except if you have few.

    In the page documentation you have the reference manual and (old) video tutorials including the two ones dedicated to Java and an other one about to write a plug-out


    Note you can also use Doxygen to make your diagram without using an UML modeler