DEV Community

Play Button Pause Button
Kevin Gilpin for AppMap

Posted on

Visualize the architecture of your Java app in IntelliJ IDEA, in 2 / minutes

AppMap is an open source IntelliJ IDEA plugin which helps you improve your code by showing you how it behaves, feature by feature, as you work. It does this by automatically generating interactive maps of architecture and code behavior right in your editor.

This 2 ¹/₂ minute video shows how to install the AppMap plugin, how to configure it to map your Java code, and how to navigate your code using the interactive diagrams.

It uses the Spring Pet Clinic as an example program.

Here are the step-by-step instructions that are demonstrated in the video, or you can follow the Quickstart for IntelliJ written instructions.

How it works

How AppMap works

AppMap works by recording code execution paths of your app and visualizing them in interactive diagrams directly in your code editor. A good way to create AppMaps is by recording unit, functional or integration test cases. The Pet Clinic project uses JUnit tests, which will be a source of AppMaps in this demo.

Install the AppMap plugin

00:12 Installing AppMap from the JetBrains Marketplace takes only a moment: 

  • Open the IntelliJ IDEA preferences
  • Select Plugins, click on the Marketplace tab and search for AppMap
  • Click on the Install button, then click on Restart IDE.

AppMap in Marketplace

When the IDE restarts, the AppMap plugin is installed and ready for viewing AppMaps.

Configure AppMap for the Pet Clinic recording

The AppMap framework uses a file called appmap.yml to determine which code to map. 

00:20 Create a new file appmap.yml in the root folder of your project. You should add all the Java packages of your project. Here is an example for the Pet Clinic application that is used in this demo:

name: PetClinic
packages:
  - path: org.springframework.samples.petclinic
Enter fullscreen mode Exit fullscreen mode

Add Java recording agent to Maven configuration

To get a recording, run the tests with an AppMap maven plugin that sets up the JVM for AppMap recording. The popular jacoco code coverage tool uses a similar approach in Maven projects.

00:54 Add the AppMap plugin to the build/plugins section of the POM:

      <!-- AppMap agent, default parameters -->
      <plugin>
        <groupId>com.appland</groupId>
        <artifactId>appmap-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-test-classes</phase>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
Enter fullscreen mode Exit fullscreen mode

Record AppMaps from tests

01:10 When you run the Maven test phase, the AppMap recording agent will record AppMaps from the tests and save them in the $buildDir/appmap folder of the project, one AppMap per each recorded test case.

$ mvnw test

Open a generated AppMap in IntelliJ IDEA

01:17 Open the AppMaps view - click on the AppMaps tab in the UI. Or, press CTRL or COMMAND + SHIFT + A, then type "AppMaps" in the search box and pick the `AppMaps View" from the list.

Select an AppMap from the list of all AppMaps found in the project folders, or search for an AppMap with a specific phrase in its name, for example "create owner".

Double click on an AppMap in the list, an interactive diagram viewer opens.

AppMap Dependency Map

Interact with the AppMap diagram

01:25 Discover how the Pet Clinic application works in the AppMap diagrams. 

  • Start with the big picture of your software design and view all code components in the Dependency Map - Web Service endpoints, Java packages/classes/functions and SQL commands and their inter-dependencies
  • Navigate to sources of classes and functions directly from the diagrams so you don't have to look for them manually
  • Drill down the execution details of code and SQL in the execution Trace.

Dependency Map

01:45 Or, you can use a bottom-up approach. Let's say you want to know what code modifies data in the database. 

  • Start with a SQL command of interest - like an INSERT
  • View how it's connected to other calls in the Trace, then backtrack to its calling component and open its source file 
  • See how it is connected to other code and Web Service endpoints.

AppMap screenshot in IntelliJ

Learn more about AppMap

This is only a small demonstration of the AppMap capabilities. For more information, step-by-step instructions and practical how-tos, check out the AppMap documentation.

Acknowledgements

Thanks to Petr and Dan for all their hard work on this video!

Top comments (5)

Collapse
 
cadams profile image
Chad Adams

Hey this is good for reverse engineering nice. 👍

Collapse
 
val09865 profile image
val09865 • Edited

The AppMap view doesn't show up for me, I have all the app map json files but it only show them as text files. How do you bring up the graphical view ?

Collapse
 
kgilpin profile image
Kevin Gilpin

Hey, if you have the AppMap extension for IntelliJ installed, then all you have to do is click on a file named *.appmap.json and it will open as visual maps. Or you can open the “AppMap” view on the left sidebar and it will list the AppMaps in the workspace. If you don’t see the AppMap extension when you search for it from inside IntelliJ, then you probably need to upgrade IntelliJ itself. Hope that helps.

Collapse
 
val09865 profile image
val09865 • Edited

This is what I did but the file just displays as text in Intellij with the AppMap plugin. Maybe AppMap depends on some other graphical component that I need to install ?

Thread Thread
 
ptrdvrk profile image
Petr

Hello @val09865 the files need to have the .appmap.json extension, i.e. test_upload.appmap.json. Can you share a screenshot of your IDE with the appmap files in the folders?