如何从Java代码生成UML图(尤其是序列图)?

本文翻译自:How to generate UML diagrams (especially sequence diagrams) from Java code?

如何从现有Java代码生成UML图(尤其是序列图)?


#1楼

参考:https://stackoom.com/question/DTG/如何从Java代码生成UML图-尤其是序列图


#2楼

EDIT: If you're a designer then Papyrus is your best choice it's very advanced and full of features, but if you just want to sketch out some UML diagrams and easy installation then ObjectAid is pretty cool and it doesn't require any plugins I just installed it over Eclipse-Java EE and works great !. 编辑:如果你是一名设计师,那么Papyrus是你最好的选择它非常先进且功能齐全,但是如果你只是想要勾勒出一些UML图并且易于安装,那么ObjectAid非常酷,它不需要任何插件我刚刚将它安装在Eclipse-Java EE上并且工作得很好!


UPDATE Oct 11th, 2013 更新2013年10月11日

My original post was in June 2012 a lot of things have changed many tools has grown and others didn't. 我的原始帖子是在2012年6月,许多事情发生了变化,许多工具已经增长,而其他工具则没有。 Since I'm going back to do some modeling and also getting some replies to the post I decided to install papyrus again and will investigate other possible UML modeling solutions again. 由于我要回去做一些建模并得到一些回复,我决定再次安装纸莎草纸,并将再次研究其他可能的UML建模解决方案。 UML generation (with synchronization feature) is really important not to software designer but to the average developer. UML生成(具有同步功能)对于软件设计者而言对于普通开发人员来说非常重要。

I wish papyrus had straightforward way to Reverse Engineer classes into UML class diagram and It would be super cool if that reverse engineering had a synchronization feature, but unfortunately papyrus project is full of features and I think developers there have already much at hand since also many actions you do over papyrus might not give you any response and just nothing happens but that's out of this question scope anyway. 我希望papyrus能够直接将Reverse Engineer类转换为UML类图,如果逆向工程具有同步功能,那将是非常酷的,但不幸的是,papyrus项目充满了各种功能,我认为那里的开发人员已经有了很多东西。你对纸莎草所采取的行动可能不会给你任何回应而且没有任何反应,但无论如何都不会出现这个问题范围。

The Answer (Oct 11th, 2013) 答案 (2013年10月11日)

Tools 工具

  1. Download Papyrus 下载纸莎草纸
  2. Go to Help -> Install New Software... 转到帮助 - >安装新软件...
  3. In the Work with: drop-down, select --All Available Sites-- Work with:下拉列表中,选择- 所有可用站点 -
  4. In the filter, type in Papyrus 在过滤器中,键入纸莎草纸
  5. After installation finishes restart Eclipse 安装完成后重启Eclipse
  6. Repeat steps 1-3 and this time, install Modisco 重复步骤1-3,这次安装Modisco

Steps 脚步

  1. In your java project (assume it's called MyProject) create a folder eg UML 在你的java项目中(假设它叫做MyProject)创建一个文件夹,例如UML
  2. Right click over the project name -> Discovery -> Discoverer -> Discover Java and inventory model from java project, a file called MyProject_kdm.xmi will be generated. 右键单击项目名称 - > Discovery - > Discoverer - >从Java项目中发现Java和库存模型,将生成一个名为MyProject_kdm.xmi的文件。
  3. Right click project name file --> new --> papyrus model -> and call it MyProject. 右键单击项目名称文件 - >新建 - >纸莎草模型 - >并将其命名为MyProject。
  4. Move the three generated files MyProject.di , MyProject.notation, MyProject.uml to the UML folder 将三个生成的文件MyProject.di,MyProject.notation,MyProject.uml移动到UML文件夹
  5. Right click on MyProject_kdm.xmi -> Discovery -> Discoverer -> Discover UML model from KDM code again you'll get a property dialog set the serialization prop to TRUE to generate a file named MyProject.uml 右键单击MyProject_kdm.xmi - > Discovery - > Discoverer - >再次从KDM代码中发现UML模型,您将获得一个属性对话框,将序列化道具设置为TRUE以生成名为MyProject.uml的文件

  6. Move generated MyProject.uml which was generated at root, to UML folder, Eclipse will ask you If you wanted to replace it click yes. 将生成的生成的MyProject.uml移动到UML文件夹,Eclipse将询问您如果要替换它,请单击是。 What we did in here was that we replaced an empty model with a generated one. 我们在这里所做的是我们用生成的模型替换了一个空模型。

  7. ALT+W -> show view -> papyrus -> model explorer ALT + W - >显示视图 - >纸莎草 - >模型浏览器

  8. In that view, you'll find your classes like in the picture 在该视图中,您将在图片中找到您的课程

  9. In the view Right click root model -> New diagram 在视图中右键单击根模型 - >新图

  10. Then start grabbing classes to the diagram from the view 然后从视图开始抓取图表中的类

Some features 一些功能

  • To show the class elements (variables, functions etc) Right click on any class -> Filters -> show/hide contents Voila !! 要显示类元素(变量,函数等)右键单击任何类 - >过滤器 - >显示/隐藏内容Voila !!

  • You can have default friendly color settings from Window -> pereferences -> papyrus -> class diagram 您可以从Window - > pereferences - > papyrus - >类图中获得默认的友好颜色设置

  • one very important setting is Arrange when you drop the classes they get a cramped right click on any empty space at a class diagram and click Arrange All 一个非常重要的设置是当您放弃类时安排他们得到一个狭窄的右键单击类图上的任何空白空间并单击全部排列

  • Arrows in the model explorer view can be grabbed to the diagram to show generalization, realization etc 可以将模型资源管理器视图中的箭头抓取到图表中以显示概括,实现等

  • After all of that your settings will show diagrams like 完成所有这些后,您的设置将显示图表

  • Synchronization isn't available as far as I know you'll need to manually import any new classes. 据我所知,您需要手动导入任何新类,因此无法进行同步。

That's all, And don't buy commercial products unless you really need it, papyrus is actually great and sophisticated instead donate or something. 这就是全部,除非你真的需要它,否则不要购买商品,纸莎草实际上是伟大而复杂的,而不是捐赠或其他东西。

Disclaimer: I've no relation to the papyrus people, in fact, I didn't like papyrus at first until I did lots of research and experienced it with some patience. 免责声明:我与纸莎草纸人没有关系,事实上,我一开始并不喜欢纸莎草纸,直到我做了很多研究并且耐心地体验了它。 And will get back to this post again when I try other free tools. 当我尝试其他免费工具时,我会再次回到这篇文章。


#3楼

By far the best tool I have used for reverse engineering, and round tripping java -> UML is Borland's Together . 到目前为止,我用于逆向工程的最佳工具,以及Java-> UML的圆形跳闸是Borland的Together 。 It is based on Eclipse (not just a single plugin) and really works well. 它基于Eclipse(不仅仅是一个插件),而且效果很好。


#4楼

I suggest PlantUML. 我建议PlantUML。 this tools is very usefull and easy to use. 这个工具非常有用且易于使用。 PlantUML have a plugin for Netbeans that you can create UML diagram from your java code. PlantUML有一个Netbeans插件,你可以从你的java代码创建UML图。

you can install PlantUML plugin in the netbeans by this method: 你可以通过这种方法在netbeans中安装PlantUML插件:

Netbeans Menu -> Tools -> Plugin Netbeans菜单 - >工具 - >插件

Now select Available Plugins and then find PlantUML and install it. 现在选择Available Plugins,然后找到PlantUML并安装它。

For more information go to website: www.plantuml.com 欲了解更多信息,请访问网站:www.plantuml.com


#5楼

I developed a maven plugin that can both, be run from CLI as a plugin goal, or import as dependency and programmatically use the parser, @see Main#main() to get the idea on how. 我开发了一个maven插件,既可以从CLI作为插件目标运行,也可以作为依赖项导入,并以编程方式使用解析器,@ @see Main#main()来了解如何使用。

It renders PlantUML src code of desired packages recursively that you can edit manually if needed (hopefully you won't). 递归地呈现所需包的PlantUML src代码 ,您可以根据需要手动编辑(希望您不会)。 Then, by pasting the code in the plantUML page, or by downloading plant's jar you can render the UML diagram as a png image. 然后,通过粘贴plantUML页面中的代码,或者通过下载工厂的jar,您可以将UML图表渲染为png图像。

Check it out here https://github.com/juanmf/Java2PlantUML 在这里查看https://github.com/juanmf/Java2PlantUML

Example output diagram: 示例输出图:

Any contribution is more than welcome. 任何贡献都非常受欢迎。 It has a set of filters that customize output but I didn't expose these yet in the plugin CLI params. 它有一组自定义输出的过滤器,但我还没有在插件CLI参数中公开它们。

It's important to note that it's not limited to your *.java files, it can render UML diagrams src from you maven dependencies as well. 重要的是要注意它不仅限于你的* .java文件,它也可以从maven依赖项中呈现UML图表src。 This is very handy to understand libraries you depend on. 这对于理解您所依赖的库非常方便。 It actually inspects compiled classes with reflection so no source needed 它实际上用反射检查编译的类,因此不需要源

Be the 1st to star it at GitHub :P 成为第一个在GitHub上演的明星:P


#6楼

How about PlantUML ? PlantUML怎么样 ? It's not for reverse engineering!!! 它不适用于逆向工程! It's for engineering before you code. 在编码之前,它是用于工程的。

你可能感兴趣的:(java,uml,diagram)