Can PlantUML generate class diagrams from Java source code ?

0 votes
asked Apr 5, 2015 in Wanted features by SantiBailors (120 points)
I am looking for a tool that can visualize the relationships between classes in my Java projects. When I read about PlantUML I see that the class diagrams it generates fit perfectly my needs but it seems to me that the only way to generate them is by writing the diagram code directly, in the "@startuml / @enduml" syntax.

Is that correct ? If yes, if someone knows about tools to generate class diagrams from existing Java code I would be interested in hearing about that.

Thanks in advance.

2 Answers

–1 vote
answered Apr 10, 2015 by gembin (250 points)

 

       Working example:

        StringBuilder plantUmlSource = new StringBuilder();

        plantUmlSource.append("@startuml\n");

        plantUmlSource.append("Alice -> Bob: Authentication Request\n");

        plantUmlSource.append("Bob --> Alice: Authentication Response\n");

        plantUmlSource.append("@enduml");

        SourceStringReader reader = new SourceStringReader(plantUmlSource.toString());

        FileOutputStream output = new FileOutputStream(new File("/your/path/to/plantuml/test.svg"));

        reader.generateImage(output, new FileFormatOption(FileFormat.SVG, false));

commented Apr 11, 2015 by anonymous
The above example shows how to use Java code to create a PlantUML language file. The original question asked for "tools to generate class diagrams from existing Java code". These are not the same thing. The question is about a tool that can analyze a Java class and create the class diagram automatically. I think I've seen some javadoc extensions that do this to same extent as well as doxygen (I think). The problem with those tools are that you get an image file, not an easy to work with text file (plantuml syntax). The textual representations used by PLantUML to generate the images are great for so many reasons.
0 votes
answered Sep 5, 2015 by graffity2199 (200 points)
Hello,

Have you tried PlantUML dependency ?

http://plantuml-depend.sourceforge.net/
...