Debugger - Java - VSCODE
Remote Debugging with Visual Studio Code (Java Application)
-
Install Visual Studio Code and required extensions:
kali@kali:~$ sudo apt install ~/Downloads/code_1.45.1-1589445302_amd64.deb
-
Set up
launch.json
for remote debugging:{ "version": "0.2.0", "configurations": [ { "type": "java", "request": "attach", "name": "Attach to Remote Program", "hostName": "127.0.0.1", "port": 8888 } ] }
2a. another Setup
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to remote",
"address": "chips",
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app"
},
{
"type": "node",
"request": "attach",
"name": "Attach to remote (cli)",
"address": "chips",
"port": 9228,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app"
}
]
}
-
Start the Java application with remote debugging:
kali@kali:~$ java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9898 -jar NumberGame.jar
-
Attach the debugger in Visual Studio Code:
- Open
MainController.java
and set a breakpoint. - Start debugging by selecting the configuration from the debug panel.
- Open
-
Verify the debugger connection and step through the code:
- Submit a request on the web page to trigger the breakpoint.
- Use the debugging context menu to step over, into, or out of code, and continue execution as needed .