Class Diagrammer for Java

Class Diagrammer 2.0 is now available for download, written in Java & JavaFX and designed to reverse-engineer Java JAR files into UML class and package diagrams. This is mostly a direct rewrite of the previous version which was written in C# and operated on .NET Framework assemblies. The download page still offers the final .NET release, too.

The new Java version relies heavily on the excellent open-source libraries of David Gilbert’s JFree. Diagrams are internally drawn using AWT, then published to JavaFX for the interactive executable via FXGraphics2D, to SVG for web pages via JFreeSVG, and to print-quality PDF documents via OrsonPDF. Check out these libraries if you need any of those output formats in your own applications.

The Class Diagrammer download package includes a small sample project based on its own JAR files. Rather than inlining a blurry bitmap or a ton of SVG code, I direct you to this PDF document (633 KB) comprising three sample diagrams. Please see the download page for a compact overview of Class Diagrammer. The rest of this post explains the rationale behind this application.

Why Class Diagrammer?

The purpose of Class Diagrammer is to create structural diagrams from computer code for documentation purposes, with as much automation as possible to ensure these diagrams stay up-to-date regarding the underlying code – the usual problem with documentation. I ended up writing my own application for this purpose because I couldn’t find anything (affordable) that handled this job properly. All existing software had one or more of the following issues:

  • Primarily intended for screen work, and thus can only export pixelated bitmap diagrams that look rather awful in otherwise crisp PDF documents.
  • Reverse engineering is not supported, or destroys much of the current diagram layout which must be laboriously recreated after each code import.
  • Reverse engineering cannot be restricted, creating a useless mess of irrelevant classes and criss-crossing relations that must be manually sorted out.
  • Reverse engineering cannot be automated, so you have to fire up some GUI application and manually redo it whenever you want to update your documentation.
  • Specific to Java: reverse engineering was implemented prior to Java 5’s reflection API, and therefore relies on unofficial tricks that break with newer Java code. This is why I had to stop using yWorks UML Doclet, an otherwise attractive solution: it was last updated for compatibility with Java 7 and does not work with Java 8 bytecode.

While overall rather limited, Class Diagrammer was specifically designed to solve all this. It relies only on the official reflection API, with no version-dependent low-level tricks. Its output formats include SVG and PDF, for crisp scalable vector graphics with perfect text rendering in HTML and PDF documents, respectively. And it can dynamically combine the Java type information found in JAR files with layout directions previously recorded in a project file.

You use a JavaFX GUI application to create a project file with your desired diagrams and output formats, then run a console application to recreate the diagram output files whenever the JAR files change after a new build. UML element contents are adjusted dynamically, and likewise UML relations which are always defined relative to element borders. You only need to manually adjust a Class Diagrammer project if you wish to add or remove elements or relations, or if your Java type information has changed so much that elements become too small or too large for your diagram design.

2 thoughts on “Class Diagrammer for Java”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.