How to debug Quarkus applications

In this article, we will learn how to debug a Quarkus application using two popular Development Environments such as IntelliJ Idea and VS Studio. We’ll explore how these IDEs can empower you to effectively identify, understand, and resolve issues within your Quarkus projects.

Enabling Debugging in Quarkus

When running in development mode, Quarkus, by default, uses port 5005 for debugging purposes. Through this port, Quarkus leverages the JPDA (Java Platform Debugger Architecture) by listening to the socket transport dt_socket thus allowing communication between a debugger and the JVM.

You can verify that Quarkus debugging is on by starting any application in dev mode. For example:

mvn quarkus:dev

This is evident from the logs:

Listening for transport dt_socket at address: 5005
2024-04-19 09:28:48,151 INFO  [io.qua.dat.dep.dev.DevServicesDatasourceProcessor] (build-8) Dev Services for default datasource (postgresql) started - container ID is a6d792af2bdd
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   

On the top of that, you can also verify it from the command line with:

lsof -i tcp:5005
COMMAND     PID      USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    2507464 francesco  120u  IPv4 24714318      0t0  TCP localhost:avt-profile-2 (LISTEN)

Finally, please note that you can change the default Port that Quarkus will use for debugging by setting the debug JVM property:

mvn quarkus:dev -Ddebug=6005

Now let’s see how to attach to the debugger process from IntelliJ Idea and Visual Studio.

Debugging from IntelliJ Idea

The first step in the debug process is setting breakpoints in the key sections of your code that you want to inspect:

quarkus debugging with intellij idea

Then, choose from the Menu: Run | Attach to Process. You will see that IntelliJ reports all the java applications listening to the socket transport dt_socket :

how to debug in intellij idea

Finally, invoke the application at a point that hits a breakpoint. You will see that IntelliJ Idea interrupts the execution and switches to Debug mode:

intellij debugging java applications step-by-step guide

Debugging from Visual Studio

In order to debug a Java application from Visual Studio, you need to have both plugins available in Visual Studio and a Launch configuration. If you are new to using Visual Studio with Java, the following cheat-sheet will speed up your learning: Visual Studio for Java CheatSheet

Then, assumed that you have the plugins to Run and Debug Java applications in Visual Studio, create a launch.json configuration. Just click on the Run and Debug left panel option and Visual Studio will suggest you to create one:

visual studio create debug configuration

Click on create a launch.json file and select a Java launch configuration. the Launch configuration contains the Quarkus Debug Port:

{
 
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Quarkus Remote Debug",
            "request": "attach",
            "hostName": "localhost",
            "port": 5005
        }
    ]
}

Finally, when you hit your breakpoints, a debugging section will start in the Call Stack lower Panel of Visual Studio:

visual studio debugging quarkus

Conclusion

Debugging Quarkus applications with IDEs like IntelliJ IDEA and Visual Studio offers a powerful and convenient approach to identify and resolve issues during development and potentially even controlled situations in production. By leveraging the hot-reload capabilities, breakpoints, and variable inspection features within these IDEs, developers can streamline their workflow and pinpoint problems efficiently.