如何在 Java 文档中绘制 UML?

发布于 2024-10-10 00:45:39 字数 1539 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-10-17 00:45:39

我尝试了 3 种方法来做到这一点,使用 maven-javadoc-plugin 和 doclet 在 JavaDocs 中生成 UML 图:

1) UmlGraphDoc

2) apiviz

3) yworks

我可以说最好的是选项 3,因为它是唯一的一个不需要在开发电脑上安装任何东西。

对于 UmlGraphDoc 和 apiviz(均为 doclet),他们需要在 PC 中安装 GraphViz。

安装它并配置 maven-javadoc-plugin 很容易,但由于它们需要一个单独的应用程序,所以它使 UML 生成有点脏,因为如果您想将 uml 生成作为 Maven 生命周期的一部分,所有其他开发人员需要安装 GraphViz(我真正想避免的依赖项)。

不管怎样,这个链接有我遵循的使用 yworks 的方法(它确实有效):

如下我的3次配置尝试,以防万一您想确认是哪一个自己更好:


第一次尝试:UmlGraphDoc

它需要安装graphviz-2.38(google一下,很容易找到
图表很丑,但可以理解!

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.2</version>
            <reportSets>
                <reportSet>
                    <id>uml</id>
                    <reports>
                        <report>javadoc</report>
                    </reports>
                    <configuration>
                        <name>uml</name>
                        <destDir>uml</destDir>
                        <quiet>true</quiet>
                        <aggregate>true</aggregate>
                        <show>private</show>
                        <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
                        <docletArtifact>
                            <groupId>org.umlgraph</groupId>
                            <artifactId>umlgraph</artifactId>
                            <version>5.6.6</version>
                        </docletArtifact>
                        <additionalparam>
                            -inferrel -inferdep -quiet -hide java.* -hide org.eclipse.* -collpackages java.util.* -postfixpackage
                            -nodefontsize 9 -nodefontpackagesize 7 -attributes -types -visibility -operations -constructors
                            -enumerations -enumconstants -views
                        </additionalparam>
                        <useStandardDocletOptions>true</useStandardDocletOptions>
                    </configuration>
                </reportSet>
            </reportSets>
        </plugin>

第二次尝试:Apiviz

需要安装 graphviz-2.38(Google 一下,很容易找到
生成的图表比第一个选项更好......

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <name>JavaDocUML</name>
                <destDir>uml</destDir>
                <doclet>org.jboss.apiviz.APIviz</doclet>
                <stylesheetfile>${basedir}/src/main/resources/javadoc/javadoc-stylesheet.css</stylesheetfile>
                <docletArtifact>
                    <groupId>org.jboss.apiviz</groupId>
                    <artifactId>apiviz</artifactId>
                    <version>1.3.2.GA</version>
                </docletArtifact>
                <useStandardDocletOptions>true</useStandardDocletOptions>
                <charset>UTF-8</charset>
                <encoding>UTF-8</encoding>
                <docencoding>UTF-8</docencoding>
                <breakiterator>true</breakiterator>
                <version>true</version>
                <author>true</author>
                <keywords>true</keywords>
                <additionalparam>
                    -sourceclasspath ${project.build.outputDirectory}
                </additionalparam>
            </configuration>
        </plugin>

第三次尝试(ywork)我推荐这个

图表更容易理解,更广泛,更酷:D
它不需要在您的电脑上安装任何东西,您只需从其网站下载 yworks-uml-doclet-3.0_02-jdk1.5 并将其放在您的 pom.xml 附近,然后使用相对路径即可找到并使用它如下:

<properties>
    <yworks.uml.path>${basedir}\..\..\tools\yworks-uml-doclet-3.0_02-jdk1.5</yworks.uml.path>
</properties>
.
.
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.2</version>
            <configuration>
                <name>JavaDocUML</name>
                <destDir>uml</destDir>
                <!-- Doclet -->
                <doclet>ydoc.doclets.YStandard</doclet>
                <docletPath>${yworks.uml.path}/lib/ydoc.jar:${yworks.uml.path}/resources:${basedir}/target/your.application.jar</docletPath>
                <additionalparam>-umlautogen</additionalparam>
                <useStandardDocletOptions>true</useStandardDocletOptions>
                <!-- bootclasspath required by Sun's JVM -->
                <bootclasspath>${sun.boot.class.path}</bootclasspath>
                <!-- General Javadoc settings -->
                <doctitle>${project.name} (${project.version})</doctitle>
                <show>private</show>
                <!-- Styling -->
                <stylesheetfile>${basedir}/src/main/resources/javadoc/javadoc-stylesheet.css</stylesheetfile>
                <docfilessubdirs>true</docfilessubdirs>
                <!-- Apple's JVM sometimes requires more memory -->
                <additionalJOption>-J-Xmx1024m</additionalJOption>
                <verbose>true</verbose>
            </configuration>
        </plugin>

I tried 3 ways of doing this, generating UML Diagrams inside the JavaDocs using maven-javadoc-plugin and doclets:

1) UmlGraphDoc

2) apiviz

3) yworks

And I may say that the best is the option 3, this because it's the only one that does not need to install something in the development pc.

For UmlGraphDoc and apiviz (both doclets) they required to install GraphViz in the PC.

Install it and configure the maven-javadoc-plugin is easy, but since they required a separate application, it turns the UML generation a bit dirty, since if you want to include the uml generation as part of your maven lifecycle, all the other developers will need to install GraphViz (A dependency that I really wanted to avoid).

Anyway, this link has the approach I followed, of using yworks (it really works):

As follows my 3 tries of configuration, just in case you want to confirm which one is better by yourself:


1st try : UmlGraphDoc

It requires to install graphviz-2.38 (google it, it's easy to find)
Diagrams are quite ugly, but understandable!!

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.2</version>
            <reportSets>
                <reportSet>
                    <id>uml</id>
                    <reports>
                        <report>javadoc</report>
                    </reports>
                    <configuration>
                        <name>uml</name>
                        <destDir>uml</destDir>
                        <quiet>true</quiet>
                        <aggregate>true</aggregate>
                        <show>private</show>
                        <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
                        <docletArtifact>
                            <groupId>org.umlgraph</groupId>
                            <artifactId>umlgraph</artifactId>
                            <version>5.6.6</version>
                        </docletArtifact>
                        <additionalparam>
                            -inferrel -inferdep -quiet -hide java.* -hide org.eclipse.* -collpackages java.util.* -postfixpackage
                            -nodefontsize 9 -nodefontpackagesize 7 -attributes -types -visibility -operations -constructors
                            -enumerations -enumconstants -views
                        </additionalparam>
                        <useStandardDocletOptions>true</useStandardDocletOptions>
                    </configuration>
                </reportSet>
            </reportSets>
        </plugin>

2nd try :Apiviz

It also requires to install graphviz-2.38 (Google it, it's easy to find)
Diagrams generated are nicer than first option...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <name>JavaDocUML</name>
                <destDir>uml</destDir>
                <doclet>org.jboss.apiviz.APIviz</doclet>
                <stylesheetfile>${basedir}/src/main/resources/javadoc/javadoc-stylesheet.css</stylesheetfile>
                <docletArtifact>
                    <groupId>org.jboss.apiviz</groupId>
                    <artifactId>apiviz</artifactId>
                    <version>1.3.2.GA</version>
                </docletArtifact>
                <useStandardDocletOptions>true</useStandardDocletOptions>
                <charset>UTF-8</charset>
                <encoding>UTF-8</encoding>
                <docencoding>UTF-8</docencoding>
                <breakiterator>true</breakiterator>
                <version>true</version>
                <author>true</author>
                <keywords>true</keywords>
                <additionalparam>
                    -sourceclasspath ${project.build.outputDirectory}
                </additionalparam>
            </configuration>
        </plugin>

3th try (ywork) (I recommend this one)

Diagrams are much more understandable and wide more cooler :D
It does not requires to install anything on your pc, you just need to download yworks-uml-doclet-3.0_02-jdk1.5 from its website and have it near your pom.xml, and using relative paths you can find it and use it as follows:

<properties>
    <yworks.uml.path>${basedir}\..\..\tools\yworks-uml-doclet-3.0_02-jdk1.5</yworks.uml.path>
</properties>
.
.
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.2</version>
            <configuration>
                <name>JavaDocUML</name>
                <destDir>uml</destDir>
                <!-- Doclet -->
                <doclet>ydoc.doclets.YStandard</doclet>
                <docletPath>${yworks.uml.path}/lib/ydoc.jar:${yworks.uml.path}/resources:${basedir}/target/your.application.jar</docletPath>
                <additionalparam>-umlautogen</additionalparam>
                <useStandardDocletOptions>true</useStandardDocletOptions>
                <!-- bootclasspath required by Sun's JVM -->
                <bootclasspath>${sun.boot.class.path}</bootclasspath>
                <!-- General Javadoc settings -->
                <doctitle>${project.name} (${project.version})</doctitle>
                <show>private</show>
                <!-- Styling -->
                <stylesheetfile>${basedir}/src/main/resources/javadoc/javadoc-stylesheet.css</stylesheetfile>
                <docfilessubdirs>true</docfilessubdirs>
                <!-- Apple's JVM sometimes requires more memory -->
                <additionalJOption>-J-Xmx1024m</additionalJOption>
                <verbose>true</verbose>
            </configuration>
        </plugin>
A君 2024-10-17 00:45:39

事实上,您提到的同一个 UMLGraph 包含 Javadoc 工具的备用 doclet,该工具将生成 UML 图作为 Javadoc 创建的一部分。我在这里找到了此信息: http://wiki.wsmoak.net/cgi-bin /wiki.pl?UMLGraph

In fact, the same UMLGraph that you mention includes an alternate doclet for the Javadoc tool that will generate UML diagrams as part of the Javadoc creation. I found this info here: http://wiki.wsmoak.net/cgi-bin/wiki.pl?UMLGraph

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文