What additional steps are required to setup Visual Studio Code to debug a Java Dropwizard app using the Java Extension Pack? I am following the instructions on the official vscode-java-debug page:
https://code.visualstudio.com/blogs/2017/09/28/java-debug
Against the official dropwizard-example application located here:
https://github.com/dropwizard/dropwizard/tree/master/dropwizard-example
When I setup the default lauch profile in vscode and then attempt to run it, the debug console prints this message:
usage: java -jar project.jar [-h] [-v] {server,check,render,db} ... positional arguments: {server,check,render,db} available commands named arguments: -h, --help show this help message and exit -v, --version show the application version and exit
It seems like there's something fundamentally different about how dropwizard apps are started that causes the default vscode debug settings not work. I'm guessing some custom launch tasks are required, but I'm having trouble finding anyone else that is using vscode against a dropwizard app.
The dropwizard application itself runs successfully using the instructions from their wiki - I just can't debug using the default vscode debug instructions. I have successfully debugged another java application using the same steps provided on the vscode debug instructions page. This is the project that worked flawlessly on the first try (Sprint Boot):
https://github.com/spring-guides/gs-spring-boot
UPDATE
(Note: I'm still interested in learning how to wire up vscode to also launch the app so I can also do things such as debug app initialization)
I found a way to start up the app in such a way that you can attach to the running process using the default vscode launch configuration. Here is the wiki page I stumbled across that shows how to use mvnDebug:
https://github.com/Microsoft/vscode-java-debug/wiki/How-to-attach-debug-maven-console-applications
The directions in that wiki page are almost what we need. Do the following instead (assuming you've already followed the directions in the vscode wiki above for the default launch.json file for java):
mvnDebug exec:java -Dexec.mainClass="com.example.helloworld.HelloWorldApplication" -Dexec.args="server example.yml"The launch.json should have something like this:
{
// 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": "Debug (Launch)-HelloWorldApplication<dropwizard-example>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "com.example.helloworld.HelloWorldApplication",
"projectName": "dropwizard-example",
"args": ""
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 8000
}
]
}
Then you should be able to hit the app the same as before but now be able to set breakpoints:
http://localhost:8080/hello-world

And also set breakpoints!
Add another configuration to launch configruations (launch.json in .vscode) as follows -
{
"type": "java",
"name": "Debug (Launch) with Arguments Prompt",
"request": "launch",
"mainClass": "{mainClass}",
"args": "server config.yml"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With