Skip to main content

Generate JavaDoc with UML diagrams

In my life many times has happened when I am assigned to a totally new project that I have no idea what it is about, that has to go live in 2 weeks and that I have to fix some issues in this ultra strange code sometimes even code written in different language.

On my question is there any documentation the answer is: Yes but it is very old or no. So in short they want me to start working on a project with no documentation at all.

My second question is is there a javadoc and the anwer is : yeah … kind of … so I am in a project with 30% javadoc with methods in French language for example ( I don’t know even a single word in French) so in short I am loosing 2 weeks to understand what is using what what is the model what is PersonnePhysique  and what is this crazy domain model.

I believe this has happened with everyone of you at least once so what can you do ?

  • You can start digging into the java code like crazy ( like everyone of us have tried many times)
  • You can install intellij idea and use the great reverse engineering way to create UML diagrams for specific classes but intelliJ idea costs money.
  • You can install netbeans 6.5 and do the same but you have to use this out dated version of NetBeans because this doesn’t exist in newer versions, thanks Oracle.
  • You can install Eclipse + MoDisco + MDT + KML to generate xmisomething file then to generate xml file with KML thingy then to use UML2 tools to view this diagram blah.
  • Or you can find some other way… this is the other way which I believe is very nice and useful and you should use it in every project that you can actually this should be the first thing that the architect should put in the project.

So in short the other way is to generate a UML diagrams each time when a javadoc is generated it will generate a UML diagrams for each class and package which contains whatever you want operations,attributes,constructors just names you can click on them and navigate using them it is AWESOME.

How this will look like ? like this:

uml1

And you can click on items for example on Category which will forward you to the Category javadoc which has a diagram as well which looks like this :

UML2

Awesome right ?

How you can do it ? In my example I will use maven so what you have to do :

use of UmlGraph

use of Graphviz

change of maven pom.xml update (for ant integration check the last link in the blog post)

1) install graphviz on the machine that will generate the javadoc .. usually this is a linux machine which runs hudson or whatever so in case of ubuntu you just need apt-get install graphviz4 otherwise you can download the msi/deb/rpg/source from here http://www.graphviz.org/Download..php then just type “dot –-help” in console to check that the dot executable is in your path.

2) update your pom.xml adding UmlGraph just add:

<plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <aggregate>true</aggregate>
                    <show>private</show>
                    <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
                    <docletArtifact>
                        <groupId>org.umlgraph</groupId>
                        <artifactId>doclet</artifactId>
                        <version>5.1</version>
                    </docletArtifact>
                    <additionalparam>
                        -inferrel -attributes -types -visibility -inferdep -quiet -hide java.* -collpackages java.util.* -qualify -postfixpackage
                        -nodefontsize 9
                        -nodefontpackagesize 7
                            </additionalparam>
                </configuration>
            </plugin>

3) invoke mvn javadoc:javadoc … and you are done. :+) easy right ? You can see explanation about all umlgraph options here http://www.umlgraph.org/doc/indexw.html like do you don’t want to see the attributes, but you want the operations and etc..

Example with operations will look like this:

 

For ant integration check http://java.dzone.com/articles/reverse-engineer-source-code-u

Comments

Anonymous said…
That's pretty cool. There's also apiviz which basically does the same thing but looks a bit more modern.
jNayden said…
yep this also looks nice :)

Popular posts from this blog

Convert PFX certificate to JKS, P12, CRT

I recently had to use a PFX certificate for client authentication (maybe another post will be coming) and for that reason I had to convert it to a Java keystore (JKS).  We will create BOTH a truststore and a keystore, because based on your needs you might need one or the other.  The difference between truststore and keystore if you are not aware is(quote from the JSSE ref guide : TrustManager: Determines whether the remote authentication credentials (and thus the connection) should be trusted. KeyManager: Determines which authentication credentials to send to the remote host. Ok that's enough what you will need is openssl and Java 7+ ;) ! First let's generate a key from the pfx file, this key is later used for p12 keystore. openssl pkcs12 -in example.pfx -nocerts -out  example .key   Enter Import Password: MAC verified OK Enter PEM pass phrase: Verifying - Enter PEM pass phrase: As shown here you will be asked for the password of the pfx file, l

Hibernate Generic DAO.

When you use Hibernate and DAO pattern it is a good idea to use a Generic Base Dao. The fallowing code snippet contains GenericDAO that is a base class for all my DAO classes. This GenericDAO uses HibernateDaoSupport from Spring for its implementation if you want you can use JpaDaoSupport or JdbcDaoSupport in your projects. My Generic DAO interface looks like this : package org.joke.myproject.dao.base; import java.io.Serializable; import java.util.List; /** * @author Naiden Gochev * @param <E> * @param <PK> */ public interface GenericDao<E,PK  extends Serializable> {     PK save(E newInstance);     void update(E transientObject);     void saveOrUpdate(E transientObject);     void delete(E persistentObject);     E findById(PK id);     List<E> findAll();     List<E> findAllByProperty(String propertyName,Object value); } All method names are very common so I don't

Patching a Maven library with your custom class.

Sometimes you use a library that has a bug. Or maybe it doesn’t has a bug but you want to change something. Of course if it is an open source you can get the sources… build them … with your change and so on. However this first takes a lot of time and second you need the sources. What you usually want .. is to just replace one class.. or few classes with something custom… maybe add a line .. or remove a line and so on. Yesterday… I had an issue with jboss-logging. The version I was using was 3.2.0Beta1 and it turns out that using this version and log4j2 2.0 final basically meant that no log is send to log4j2. The reason was a null pointer exception that was catched in jboss logging class called Log4j2Logger. The bug I submitted is here https://issues.jboss.org/browse/JBLOGGING-107 and it was fixed at the same day. However I will use it as an example since I didn’t knew when this will be fixed.. and I didn’t want to wait till it is fixed. So I was thinking what I want.. to take the j