本文介紹了如果在 Eclipse 中安裝、使用 PlantUML 插件,來進行常用 UML 圖的繪制。
PlantUML 簡介
PlantUML 是一個開源項目,通過簡單并帶指引性語言定義來定義各種視圖。該工具支持快速繪制以下 UML 圖:
時序圖
用例圖
類圖
活動圖
組件圖
狀態(tài)圖
部署圖
對象圖
線框圖形界面
PlantUML 支持多個中 IDE 的集成,比如 Eclipse、NetBeans、Intellij idea 等。
安裝 PlantUML for Eclipse 插件
PlantUML for Eclipse 插件主要用于在 Eclipse 中使用 PlantUML。在 Eclipse 的插件市場中安裝,點擊 “Help/Install new software”,在 Eclipse 4 (Juno) 及以上版本中,插件安裝地址為:
http://plantuml.sourceforge.net/updatesitejuno/
http://basar.idi.ntnu.no/svn/tdt4100/anonymous/trunk/updatesite/
點擊“Window/Show View/Other..”,可以將 PlantUML 預(yù)覽窗口面板顯示出來。
安裝 Graphviz
下載地址:http://www.graphviz.org/Download_windows.php;有時官網(wǎng)下載速度也很慢,也可以到我的網(wǎng)盤下載 https://pan.baidu.com/s/1gfvBC9X
安裝 Graphviz 完成后,在 Eclipse 的 PlantUML 中,設(shè)置路徑到 Graphviz 的 dot.exe。 如下圖:
如果 Graphviz 沒有安裝 成功,或者配置路徑錯誤,則會有如下錯誤提示。
PlantUML 的使用
在 Eclipse 中編輯如下腳本:
@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml
PlantUML 插件會自動識別上述腳本,從而在預(yù)覽窗口生成一張時序圖圖片。該圖片可以被用于導(dǎo)出、復(fù)制、打印。