Skip to content

Latest commit

 

History

History
 
 

README.md

title How to Debug Java with VSCode
permalink /java/

How to Debug Java with VSCode

Summary

Basic

Spec

  • 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

unit test (Junit)

launch.json

{
	"version": "0.2.0",
	"configurations": [
		{
            "type": "java",
            "name": "Test Debug (Launch)",
            "request": "launch",
            "mainClass": "junit.textui.TestRunner",
            "args": "com.j74th.vscodedebugbook.bubblesort.BubbleSortTest"
		}
	]
}

executable file debug

launch.json

{
	"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

launch.json

{
	"version": "0.2.0",
	"configurations": [
		{
            "type": "java",
            "name": "Debug (Attach)",
            "request": "attach",
            "hostName": "localhost",
            "port": 5005
		}
	]
}

how-to

  1. run program with debug option
    • set suspend=y when you like to stop before attach, othrewise 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
  1. start debug