How to Debug Java with VS Code
- OS
_ ✅ MacOS
_ ✅ Windows * ? Linux
- Break Point
_ ✅ break point
_ ✅ condition break point * ❌ function breakpoint
- Step Execution
_ ✅ Step Over
_ ✅ Step Into
_ ✅ Step Out
_ ✅ Continue
_ ❌ Step Back
_ ❌ Move To * ❌ Pause
- Variables
_ ✅ variables views
_ ✅ watch variables
- Call Stack * ✅ call stack
- Evaluation
_ ✅ eval expression to show variables
_ ✅ eval expression to change variables
- Type of Execution
_ ✅ debug unit test
_ ✅ debug executable package * ✅ remote debugging
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Test Debug (Launch)",
"request": "launch",
"mainClass": "junit.textui.TestRunner",
"args": "com.j74th.vscodedebugbook.bubblesort.BubbleSortTest"
}
]
}
- Install OpenJDK or OracleJDK
- set JDK path to environment value JAVA_HOME
- set JDK/bin path to PATH
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)",
"request": "launch",
"mainClass": "com.j74th.vscodedebugbook.bubblesort.BubbleSorter",
"args": "4 3 2 1"
}
]
}
attach running and remote process
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "192.168.1.24",
"port": 5005
}
]
}
- run program with debug option
- set
suspend=y
when you like to stop before attach, otherwise suspend=n
when you like to start right away.
java -cp target/classes -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=5005,suspend=y com.j74th.vscodedebugbook.bubblesort.BubbleSorter 4 3 2 1
- start debug