I was able to debug a simple Java hello world. The first step was to "compile" with javac -g. I looked up how I would acomplish the same with maven and found http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-debug.html, but those instructions are for running the application and wait for a debugger to connect.
I also tried to use target/classes for classpath in launch.json. The debugger complains that it cannot find a file in the root directory /, but it runs. Althought the debugger is running, the application is not responding to HTTP requests.
Is there a mvn command to compile the application with javac -g and produce a .class the debugger is able to run successfully?
You will only be able to remote debug with vs code, so a simple command will be mvnDebug spring-boot:run, which will do the same thing as mvn spring-boot:run but add these options:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
Then you can attach from vs code, a sample launch.json looks like:
{
"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) from the debug panel to run.
Assuming you've installed the collection package Java Extension Pack by Microsoft debugging Maven Spring Boot applications seems to work right-out-of-the-box.
Launch code from the project's root directory and "Start Debugging". There are multiple ways to launch the debbugger -- the most straightforward is to just hit F5 and, if it asks, select Java.
Under nominal conditions this triggers the following steps:
main function -- which should include SpringApplication.run()Related links: