Search code examples
javaamazon-web-servicesspring-bootdebuggingaws-cloud9

How do I attach a debugger to my Spring Boot application in AWS Cloud9?


I am using AWS's Cloud9 IDE to work on a Spring Boot application.

I have created a "shell command" run configuration that uses the following command to start my application:

mvn spring-boot:run -f pom.xml -DlogPathProperty=/path/to/log/directory

The Cloud9 debugger does not seem to attach to my program by default when I run it this way. Because I'm not using "Runner: Auto" (which appears to do precisely nothing in my environment), I cannot click the bug icon to turn on the debugger.

Research suggests that I should be able to run the above command using mvnDebug instead of mvn and then I should be able to attach a debugger, but I'd really like to be able to use the debugger that's built into the IDE. The AWS Cloud9 documentation is pretty opaque, so I could really use some help from a human.


Solution

  • First, click Edit launch configurations and then add the below snippet. And then run "mvnDebug spring-boot:run" It will start listening to the port 8000 and you can click the drop down adjacent to Run button to attach the debugger.

    {
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Attach)",
            "request": "attach",
            "hostName": "localhost",
            "port": 8000
        },
        {
            "type": "java",
            "name": "Debug (Launch)",
            "request": "launch",
            "mainClass": "",
            "args": ""
        }
    ],
    "version": "0.2.0"
    

    }

    Snapshot below.

    enter image description here

    And then you should be able to debug the application.

    enter image description here