How to debug Java maven spring-boot application in vs code?

I was able to debug the simple Java hello world. The first step was to "compile" with javac -g. I looked at how I would do this with maven and found http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-debug.html , but these instructions are for starting the application and waiting for the debugger to connect.

I also tried to use target/classesfor classpathin launch.json. The debugger complains that it cannot find the file in the root directory /, but it works. Although the debugger is running, the application does not respond to HTTP requests.

Is there a command mvnto compile the application with javac -gand create .classthat the debugger can successfully execute?

+4
source share
1 answer

Remote debugging is only removed using the vs code, so there will be a simple command mvnDebug spring-boot:runthat will do the same thing as mvn spring-boot:run, but adds the following parameters:

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y

Then you can attach the vs code, the launch.json sample looks like this:

{
 "version": "0.2.0",
  "configurations": [

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

and you can select Debug(Attach)in the debug panel to run.

+2
source

Source: https://habr.com/ru/post/1674471/


All Articles