0

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.

Yost777
  • 597
  • 1
  • 6
  • 19
  • What is missing when using the IntelliJ visualiser? – tschaka1904 Sep 27 '19 at 12:44
  • There is tools for this but they are not free. Some of them propose a free/community version with less functionalities so you maybe have to redo the missing functionalities. – Red Beard Sep 27 '19 at 13:12
  • Try Visual Paradigm, its free version is fully functional for first 30 days. – Avinash Sagar Sep 27 '19 at 13:27
  • 1
    Questions starting with "Is there any" are regarded off-topic here. – qwerty_so Sep 27 '19 at 15:01
  • Thanks for the comments, unfortunately IMHO these are not viable solutions (and a trial does not equate to free). As extremely similar questions have been posted here I do think this may be relevant to the coding community? – Yost777 Sep 27 '19 at 16:59
  • For completeness see https://stackoverflow.com/questions/6302490/eclipse-plugin-for-generating-a-class-diagram (Fully support making stack overflow a more welcoming community - especially for non-experts) – Yost777 Sep 30 '19 at 21:56

2 Answers2

2

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

bruno
  • 32,421
  • 7
  • 25
  • 37
  • Thank you bruno for your answer, I'm guessing there is an additional action between the 2nd and 3rd point, perhaps Tools -> Reverse Engineering Java? I did this, generating a populated hierarchy of my project, but when clicking/creating a new class diagram, it always shows empty. – Yost777 Sep 30 '19 at 16:44
  • 1
    @Yost777 yes you are right I missed the call of the reverse (funny). Of course when you create a diagram it is empty, there is no magic crystal ball to know what you want, the last two steps in the first list (*use the button binocular..* and *into the open diagram..*) mark all classes to place them into the diagram – bruno Sep 30 '19 at 20:53
  • thank you for elaborating - that works (also good to find that icon was portraying binoculars!) I was also able to get Doxygen working with GraphViz, though it only appears to visualise the directly connected classes for a single class. So, so far BoUML is the best option that indeed does the job including a fair amount of customisation, though it does seem for a complete class overview something better could be produced. – Yost777 Sep 30 '19 at 21:23
0

Although BoUML does an ok job on this, for a large project it's not pretty.

For a better solution to fully automatically create a basic but complete class diagram from source code, try the simple extractor I put together in Java: https://github.com/folterj/ClassDiagramExtractor

The project uses reflection, and produces a diagram from all the packages in a folder (and sub-folders).

Notes:

  • No command line options - clone & run setting source folder in code
  • This produces a gv file for use with GraphViz (dot), available here: https://www.graphviz.org/

The result looks quite good, as it groups packages together and even uses coloring.

Yost777
  • 597
  • 1
  • 6
  • 19