Code Refactoring, How to, Neo4j Desktop, Use Cases

How to Visualize Java Source Code with Graphlytic and jQAssistant

09.12.2021
How to Visualize Java Source Code with Graphlytic and jQAssistant

Looking at source code in the form of a graph can bring multiple benefits for the team. From routine checks for forbidden patterns to checking cross-module dependencies or refactoring workload estimations. Some tasks can be at least partially automatized and in others, information for decision making can be obtained much faster and in the form of interactive graph visualization.

This post will show how to quickly set up graph visualization of a Java codebase using Maven, jQAssistant, Neo4j graph database, and Graphlytic Desktop.

The setup involves several steps:

  1. Installing jQAssistant in your Maven project
  2. Generating a graph from your Java source code
  3. Running the embedded jQAssistant's Neo4j server with the graph
  4. Connecting Graphlytic Desktop to the Neo4j server (using Neo4j Desktop)
  5. Exploring the graph with Graphlytic's visualization

 

1. Installing jQAssistant in your Maven project

To install jQAssistance in your Maven project simply add the plugin dependency into your pom.xml file:

<properties>
   <jqassistant.version>1.11.1</jqassistant.version>
</properties>

<build>
   <plugins>
      <plugin>
         <groupId>com.buschmais.jqassistant</groupId>
         <artifactId>jqassistant-maven-plugin</artifactId>
         <version>${jqassistant.version}</version>
         <executions>
            <execution>
               <goals>
                  <goal>scan</goal>
                  <goal>analyze</goal>
               </goals>
               <configuration>
                  <warnOnSeverity>MINOR</warnOnSeverity>
                  <failOnSeverity>MAJOR</failOnSeverity>
               </configuration>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>

 

2. Generating a graph from your Java source code

The jQAssistant is re-generating the graph from the Java source code every time the project is built. The Neo4j graph database is used as the storage for the graph, the generated database folder can be found in the /target/jqassistant/store folder in your Java project after running:

mvn clean install -DskipTests

 

3. Running the embedded jQAssistant's Neo4j server with the graph

To bring the graph to the life you can either copy the generated /store folder into an existing Neo4j server or you can simply run the jQAssistant's embedded Neo4j server (do not forget to stop the Neo4j server before running any other Maven commands).

To start the embedded jQAssistant's Neo4j server run:

mvn jqassistant:server

 

4. Connecting Graphlytic Desktop to the Neo4j server (using Neo4j Desktop)

Neo4j discontinued 3rd party applications in Neo4j Desktop. Please use a locally installed Graphlytic server (the LITE version is free).

Add the running graph in Neo4j Desktop as a remote graph

The jQAssistant's embedded Neo4j is a 3.5.x version with default settings:

  • Connect URL: bolt://localhost:7687
  • Username: neo4j
  • Password: admin

To add this graph into Neo4j Desktop we can simply add it as a remote database and then run Graphlytic Desktop (see clip below).

Do not forget to change the Neo4j connection type to Neo4j 3 in Graphlytic's Settings.

Adding a remote Neo4j database in Neo4j Desktop and running Graphlytic Desktop

 

5. Exploring the graph with Graphlytic's visualization

Now we can make our first visualization and start looking into the graph. To use the fulltext search we need to configure the Neo4j fulltext index first and then we can search for specific classes or methods in the graph.

Exploring the jQAssistant graph in Graphlytic Desktop

 

Style your graph

Adding icons or colors to your visualization is always a good idea and can greatly help in a faster understanding of the data. Take a look at this blog post to learn the styling basics in Graphlytic.

 

Generate graph projections as subgraphs

The jQAssistant generated graph has a great level of detail. In fact, it's so highly connected and structured that it may be sometimes hard to find the answer to simpler questions because it's buried in a maze of relationships and intermediary nodes that are not necessary for the task at hand. For such situations, we can use graph projections that can simplify the graph for specific purposes. To learn more take a look at a few examples in this blog post: Graph Projections Automation with Graphlytic. The graph model used in the examples is the same jQAssistant graph that we have constructed in this post.

 

Blog subscription

We'll send you a notification email when a new blogpost is published. Emails may contain also commercial informations. Your email is safe with us, we will not spam you, and you will be able to unsubscribe anytime.

Thank you, your subscription has been received!
    Oops! Something went wrong while submitting the form.

    Popular posts

    Code Refactoring, How to, Neo4j Desktop, Use Cases

    What's New in Graphlytic 4.1

    13.04.2023
    Code Refactoring, How to, Neo4j Desktop, Use Cases

    Introducing Graphlytic LITE Server

    05.10.2021
    Code Refactoring, How to, Neo4j Desktop, Use Cases

    How to embed Graphlytic visualization into your app using iframe

    19.10.2021