如何从现有的Java代码生成UML图(特别是序列图)?
当前回答
我开发了一个maven插件,它既可以作为插件目标从CLI运行,也可以作为依赖项导入,并以编程方式使用解析器,@see Main# Main()来了解如何运行。
它递归地呈现所需包的PlantUML src代码,如果需要,您可以手动编辑(希望您不会)。然后,通过将代码粘贴到plantUML页面中,或者通过下载plant的jar,您可以将UML图呈现为png图像。
点击https://github.com/juanmf/Java2PlantUML查看
示例输出图:
欢迎任何捐助。它有一组自定义输出的过滤器,但我还没有在插件的CLI参数中公开这些过滤器。
值得注意的是,它并不局限于您的*.java文件,它也可以从maven依赖项中渲染UML图。这对于理解您所依赖的库非常方便。它实际上检查带有反射的已编译类,因此不需要源
成为第一个在GitHub上的明星:P
其他回答
我推荐PlantUML。这个工具非常有用,很容易使用。PlantUML有一个Netbeans插件,你可以用你的java代码创建UML图。
在netbeans中安装PlantUML插件的方法如下:
Netbeans菜单->工具->插件
现在选择可用插件,然后找到PlantUML并安装它。
更多信息请访问网站:www.plantuml.com
我是作者之一,所以答案可能有偏见。它是开源的(Apache 2.0),但是插件不是免费的。如果你克隆并在本地构建它,你就不需要付费。
在Intellij IDEA上,ZenUML可以从Java代码生成序列图。
请登录https://plugins.jetbrains.com/plugin/12437-zenuml-support查看
源代码:https://github.com/ZenUml/jetbrains-zenuml
我发现绿色插件非常简单,使用和生成类图从源代码。 试一试吧。 只需将插件复制到插件目录。
使用IntelliJ IDEA。要生成类图,选择package并按Ctrl + Alt + U:
默认情况下,它只显示类名,而不显示所有依赖项。要更改它:右键单击->显示类别…和显示依赖项:
要生成依赖关系图(UML部署图),使用maven go View -> Tool Windows -> maven Projects,并按Ctrl + Alt + U:
结果:
此外,还可以生成更多其他图表。见文档。
ObjectAid UML Explorer
是我用的。它很容易从存储库安装:
Name: ObjectAid UML Explorer
Location: http://www.objectaid.com/update/current
并生成相当不错的UML图:
网站描述:
The ObjectAid UML Explorer is different from other UML tools. It uses the UML notation to show a graphical representation of existing code that is as accurate and up-to-date as your text editor, while being very easy to use. Several unique features make this possible: Your source code and libraries are the model that is displayed, they are not reverse engineered into a different format. If you update your code in Eclipse, your diagram is updated as well; there is no need to reverse engineer source code. Refactoring updates your diagram as well as your source code. When you rename a field or move a class, your diagram simply reflects the changes without going out of sync. All diagrams in your Eclipse workspace are updated with refactoring changes as appropriate. If necessary, they are checked out of your version control system. Diagrams are fully integrated into the Eclipse IDE. You can drag Java classes from any other view onto the diagram, and diagram-related information is shown in other views wherever applicable.
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- 从现有模式生成表关系图(SQL Server)
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder