Software Development

Class diagram generation from Java source

UMLGraph allows the declarative specification and drawing of UML class and sequence diagrams. The specification is done in text diagrams, that are then transformed into the appropriate graphical representations.
UMLGraph is implemented as a javadoc doclet (a program satisfying the doclet API that specifies the content and format of the output generated by the javadoc tool). Furthermore, the output of UMLGraph needs to be post-processed with the Graphviz dot program. Therefore, to draw class diagrams with UMLGraph class you will need to have javadoc and Graphviz installed on your computer.

Maven plugin details

UMLGraph can be easily integrated with existing maven based application. Below is the maven plugin details which needs to be configured:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <configuration>
    <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
    <docletArtifact>
      <groupId>org.umlgraph</groupId>
      <artifactId>doclet</artifactId>
      <version>5.1</version>
    </docletArtifact>
    <additionalparam>-horizontal -attributes -enumconstants -enumerations -operations -types -visibility -inferrel -inferdep -hide java.* -inferrel -collpackages java.util.*</additionalparam>
    <show>public</show>
  </configuration>
</plugin>

UMLGraph depends upon Graphviz which must be already installed on the machine. Also in the above maven setting if you configure ‘GRAPHVIZ_HOME’ environment variable you need not specify the docletpath in plugin details.

Steps to configure UMLGraph

  1. Download and install Graphviz
  2. Set GRAPHVIZ_HOME environment variable.
  3. Add the above plugin details in your POM.xml, configure additionalparams per your need.
  4. execute ‘mvn javadoc:javadoc’.

Sample 

Below is the sample generated using above configuration over our Pizza entity pizza_class_diagram.png

More configuration

You can configure this diagram per your needs. Please refer UMLGraph class diagram options for more configuration.

Reference: Class diagram generation from Java source from our JCG partner Abhishek Jain at the NS.Infra blog.

Abhishek Jain

Abhishek is a lead software engineer with Impetus Technologies, pioneered in outsource product development. He has technical expertise in designing and implementing solutions around distributed application, database technologies, middle-ware technologies and SaaS platform.
Subscribe
Notify of
guest

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

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button