Configure the attach debug for Quarkus in Visual Studio Code

This blog post is a short cheat sheet for:

  • How to simply organize workspaces and the debugging configuration separated from source code saved in GitHub.
  • How to simply configure attach debug for Quarkus in Visual Studio Code

The advantage with that organization is:

You can easily delete the source code saved in GitHub from your local machine, but you don’t lose the debugging or other configurations you did.

In case that you will work again on the source code of the deleted GitHub project, you don’t need to setup these configurations again, because you can just add/link cloned GitHub source code project once more to your Visual Studio Code workspace project, which is still on your local machine.

Step 1: Create a root folder for the Visual Studio Code  workspaces and configurations projects

Separate the Visual Studio Code configurations from the GitHub source code projects. So, we have a root folder for Visual Studio Code configuration and workspace files and one root folder for the GitHub projects.

Example names:

Folder NameComment
vsc-workspacesRoot folder for the Visual Studio Code configurations projects
devRoot folder for the GitHub source code projects

Step 2: Create a folder for a Visual Studio Code workspace project and add the GitHub project folders

In this example situation I used cns-workspace for the cloud native starter workspace project.

The two folder names vsc-workspaces/cns-workspace.

Folder NameComment
vsc-workspacesRoot folder for all  Visual Studio Code configurations projects.
cns-workspaceOne concrete workspace project folder, which is mainly for the configurations and workspace files.
The GitHub source code project folders, will only be linked in the next step to that workspace project.

In the image you see two cloud native starter (cns) GitHub projects and the newly created workspace project.

Step 3: Save the workspace file

In this example situation I use cns-workspace project, where I save my configurations.
The workspace file name (cns-workspace.code-workspace) and the folders:

  • vsc-workspaces/cns-workspace/cns-workspace.code-workspace

Step 4: Add debug configuration to the Visual Studio Code workspace

Ensure the extension pack “Java Extension Pack” is installed. That also includes following extensions and more:

Add the debug configuration to the launch.json file.

In the following image you see folder structure used for that example.

Here is content of launch.json file.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [     
        {
            "type": "java",
            "name": "Remote Debug (Attach Quarkus)",
            "request": "attach",
            "hostName": "localhost",
            "port": 5005
        },
        {
            "type": "java",
            "name": "Remote Debug (Attach OpenLiberty)",
            "request": "attach",
            "hostName": "localhost",
            "port": 7777
        },
        {
            "type": "java",
            "name": "Launch Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
    ]
}

Step 5: Start your Quarkus application and debug

Ensure you have an active breakpoint in your source code.

The gif below shows following steps:

  1. Start Quarkus in the development mode.
    With: mvn clean package quarkus:dev
  2. Attach the debugger to port 5005
  3. Change to the debug view in Visual Studio Code
  4. Invoke a REST endpoint of the mircoservice
  5. Debug the mircoservice running in Quarkus


I hope this was useful for you and let’s see what’s next?

Greetings,

Thomas

#quarkus, #visulstudiocode, #vscode, #java, #debug

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.