Create uml from java

How to Generate UML from Java (Round-Trip)?

Round-trip engineering is the ability to generate model from source code and generate source code from model, and keep them synchronized. You can make use of round-trip engineering to keep your implementation model and source code up-to-date, so as to produce up-to-date description on your model.

Generate/Update UML classes from code

You can produce UML classes from source code, or to update from code all the reversed UML classes in project. To do this:

  1. Select Tools > Code > Reverse Java Code. from the toolbar.
  2. In the Reverse Code dialog box, specify the mapping between source path and model. Model is a UML element that acts as a container of other elements. You can place the UML classes to be produced to specific model for better categorization. For example, you may create a Prototype model and an Implementation model for storing classes developed in prototype and implementation phrases respectively. Once a mapping is defined, round-trip engineering will be performed between the model and path as defined. You can add multiple Source-path-to-model mapping by pressing the + button. If you do not use model to structure your project, keep model to be .
    The mappings between source paths and model are defined
    The mappings between source paths and model are defined
  3. By default, an on-demand reverse engineering will be carried out, which means to form indexes to the added path(s) instead of actually reversing them. For details about on demand reverse engineering, refer to the section below. If you want to carry out actual reverse engineering, uncheck Reverse source on demand.
  4. Click OK to proceed with reversal.

Updating UML classes on a class diagram from code

Once you have performed round-trip engineering for once, you can update UML class(es) on a diagram from source code for reflecting the changes made in code. To update, right click on the background of the class diagram for update and select Utilities > Java Round-trip > Reverse Code from the popup menu.

NOTE: In order to trigger this function, make sure you have performed round-trip engineering at least for once and the diagram has at least one class.

Updating specific UML classes from code

Once you have performed round-trip engineering for once, you can update specific UML class(es) from source code for reflecting the changes made on that particular class(es) To update, select in class diagram the UML class(es) you want to update. Right click on them and select Java Round-trip > Reverse Code from the popup menu.

An overview of Reverse Code dialog box

On-demand reverse engineering

Consider if you have a project that contains million of Java source file, and now you want to re-develop just a few classes in it. If you try to reverse the whole project it will take you a long time to complete the reverse due to the amount of classes (and relationships) are just too many. With on-demand reverse engineering, you will reverse the sources as indexes, and obtain an index tree in class repository. No actual UML classes will be reversed until you trigger the reverse manually. This reduces the processing time significantly.

To perform on-demand reverse engineering, make sure the option Reverse source on demand is checked in the Reverse Code dialog box.

The option Reverse source on demand that appear in reverse dialog box
The option Reverse source on demand that appear in reverse dialog box

When finished reverse, you can lookup the index tree in class repository. Then, right click on the class you want to reverse and select Reverse Resources to where Resources are the classes you have selected, and select either New Class Diagram or Class Repository from popup menu. Both options will result in reversing the selection to UML classes, while the option New Class Diagram will create a class diagram and place the classes in it.

Reverse a java source file from index tree
Reverse a java source file from index tree

The following resources may help you learn more about the topic discussed in this page.

Источник

Java to UML Diagram

Java to UML Diagram

Many plugins can convert the Java code to UML class and other diagrams. This tutorial demonstrates installing the plugins and converting the Java code to a UML diagram.

Convert Java Project to a UML Diagram

Eclipse has many plugins used to convert the Java code to UML diagrams. UML Lab Modeling IDE is one of the best plugins to convert the Java code to UML in Eclipse.

Let’s see how to install and use the plugin.

Open Eclipse Marketplace from the Help menu and search UML Lab Modeling

First Step

Click Install on UML Lab Modeling IDE

Install UML Lab Modeling IDE

Click Confirm to process the installation.

Confirm Installation

The next step is to accept the license agreement and click Finish .

accept the license agreement

The UML Modeling IDE will be installed in Eclipse in a while.

Installing software

Once the installation is finished, Eclipse will ask you to restart to use the plugin. Restart Eclipse.
The next step is to run the UML Modeling IDE, right-click on the project name, select UML Lab , and select Reverse Engineer the Selected Files into Modal and Diagram .

run the UML Modeling IDE

Select the files of the project you want to add to the class diagram and click Finish .

Select Project

Finally, you will be able to see the class diagram you want.

class diagram

We selected our delftstack demos project to show the Java code in UML Class diagrams. The UML Modeling IDE is a paid software for users other than academics.

It offers one day trial, but it is free for academic use. You have to provide the academic information to subscribe.

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

Related Article — Java UML

Источник

How to generate UML diagrams (especially sequence diagrams) from Java code?

@BillK my answer does address sequence diagrams. It is a Intellij Idea plugin — stackoverflow.com/a/45239269/529187.

16 Answers 16

ObjectAid UML Explorer

Is what I used. It is easily installed from the repository:

Name: ObjectAid UML Explorer Location: http://www.objectaid.com/update/current 

And produces quite nice UML diagrams:

Screenshot

Description from the website:

  • 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.

HowTo >>> Create account here: objectaid.com/login (activation email was send in 10minutes), Click Diagram Add-On, licence will be send to your email. Follow this objectaid.com/installation to install ObjectAid, then install GEF from download.eclipse.org/tools/gef/updates/releases Now copy-paste licence from email to Window->Preferences->ObjectAid How to create diagram? objectaid.com/class-diagram

Cannot install in eclipse juno. An error occurred while installing the items session context was:(profile=epp.package.java, phase=org.eclipse.equinox.internal.p2.engine.phases.Install, operand=null —> [R]com.objectaid.uml 1.1.3, action=). Failed to prepare partial IU: [R]com.objectaid.uml 1.1.3.

Commercial version of ObjectAid can do better when it comes to sequence diagram generation vs free can only be used to generate class diagrams !!

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 !.

UPDATE Oct 11th, 2013

My original post was in June 2012 a lot of things have changed many tools has grown and others didn’t. 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 generation (with synchronization feature) is really important not to software designer but to the average developer.

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.

The Answer (Oct 11th, 2013)

  1. Download Papyrus
  2. Go to Help -> Install New Software.
  3. In the Work with: drop-down, select —All Available Sites—
  4. In the filter, type in Papyrus
  5. After installation finishes restart Eclipse
  6. Repeat steps 1-3 and this time, install Modisco
  1. In your java project (assume it’s called MyProject) create a folder e.g 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. enter image description here
  3. Right click project name file —> new —> papyrus model -> and call it MyProject.
  4. Move the three generated files MyProject.di , MyProject.notation, MyProject.uml to the UML folder
  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 enter image description here
  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. What we did in here was that we replaced an empty model with a generated one.
  7. ALT+W -> show view -> papyrus -> model explorer
  8. In that view, you’ll find your classes like in the picture enter image description here
  9. In the view Right click root model -> New diagram enter image description here
  10. Then start grabbing classes to the diagram from the view

Some features

enter image description here

  • To show the class elements (variables, functions etc) Right click on any class -> Filters -> show/hide contents Voila !!
  • You can have default friendly color settings from Window -> pereferences -> papyrus -> class diagram
  • 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.

Источник

Читайте также:  Materialize css select search
Оцените статью