Search code examples
javavisual-studio-codejdb

How do you attach to a remote Java debugger using Visual Studio Code


I am trying to configure Visual Studio Code so that I can use it instead of IJ for debugging a complex Java app. Because of reasons too complicated to get into, I have been running on a terminal using mvnDebug then connecting using JDB. In IJ I set this up as a remote debugger, however, I can't seem to find the same option in VSC.

I have tried this extension, but I can't figure out how to configure it for just JDB (I shouldn't need startupClass etc).

How do I use JDB with Visual Studio Code?


Solution

  • Create a Debug Configuration like below and press F5 to debug :

    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Attach)",
            "projectName": "Your_Project_Name",
            "request": "attach",
            "hostName": "your_host_name",
            "port": Debugging_port
        }
    ]
    

    Example :

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

    I am using wildfly server. So the default debugging port is 8787.