I'm trying to set up remote debugging for a Java application in Neovim using nvim-dap
. However, when I try to attach the debugger, I get the following error:
Error 09:21:30 notify.error DAP Error on attach: Failed to attach to remote debuggee VM. Reason: java.ConnectException: Connection refused
Neovim Configuration
I'm using the extra plugin lang.java
from LazyVim, which contains the following configuration for nvim-dap
:
{
"mfussenegger/nvim-dap",
optional = true,
opts = function()
local dap = require("dap")
dap.configurations.java = {
{
type = "java",
request = "attach",
name = "Debug (Attach) - Remote",
hostName = "127.0.0.1",
port = 5005,
},
}
end,
dependencies = {
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "java-debug-adapter", "java-test" } },
},
},
}
What I Tried
If I manually start the JVM with the following command before attaching the debugger, nvim-dap
works correctly:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -cp bin exemplo.Autodromo
This makes the JVM start and wait on port 5005:
Listening for transport dt_socket at address: 5005
But if I try to start the debugger in Neovim without this manual step, I get the "Connection refused" error.
Question
What could be causing this issue? Is there any additional configuration I need to adjust so that nvim-dap
can correctly attach to the Java process without manually starting the JVM with -agentlib:jdwp
?