Please help setup configure nvim-jdtls (the debugger for java in nvim, with nvim-dap)

I’ve installed most of the supposedly required packages, however the configuration instructions are fragmented across multiple github pages and is confusing. The documentation is not clear on what files to modify.

In the end all I want is to use nvim-dap with nvim-jdtls, (for debugging a java program) but then I had to install java-debug, and eclipse.jdt.ls and I am stuck not knowing how to connect these together.


I’ve installed nvim-dap
when I type :h dap-configuration , it brings up text. Under ‘adapter configuration’ section it says : to register so-and-so adapter under type (im guessing) java : I have to put some code similar to

lua << EOF
    local dap = require('dap')
    dap.adapters.python = {
      type = 'executable';
      command = os.getenv('HOME') .. '/.virtualenvs/tools/bin/python';
      args = { '-m', 'debugpy.adapter' };
    }
    EOF

in some file. I’m guessing this is ‘init.vim’ ? I don’t know what the command = os.getenv(‘HOME’) path is supposed to be.
I’m hoping ‘debugee configuration’ is also to go in init.vim file?


I’ve installed ’ nvim-jdtls '
on the github page, it says, for debugger (via nvim-dap)
" For 1 & 2 to work, eclipse.jdt.ls needs to load the java-debug extension. "

java-debug installation :
I’m supposed to " Extend the initializationOptions with which you start eclipse.jdt.ls "
with this :

config['init_options'] = {
  bundles = {
    vim.fn.glob("path/to/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
  };
}

Where is this ’ initializationOptions ’ ??? where am I supposed to put the above code?

** nvim-jdtls ( nvim-dap setup ) **

It says, extend the configuration for nvim-jdtls with:

config['on_attach'] = function(client, bufnr)
  -- With `hotcodereplace = 'auto' the debug adapter will try to apply code changes
  -- you make during a debug session immediately.
  -- Remove the option if you do not want that.
  require('jdtls').setup_dap({ hotcodereplace = 'auto' })
end

what is the name of this ’ configuration for nvim-jdtls ’ file ???


I’ve installed java-debug

it also talks about initializationOptions,

Usage with eclipse.jdt.ls

" To use java-debug as a jdt.ls plugin, an LSP client has to launch jdt.ls with initializationOptions that contain the path to the built java-debug jar within a bundles array: "

so where am I supposed to put the code below that ??

" Once eclipse.jdt.ls launched, the client can send a Command to the server to start a debug session: "

{
  "command": "vscode.java.startDebugSession"
}

so where is this code supposed to be?


I’ve installed eclipse.jdt.ls, and apparently I’m suppsed to edit ~/.bashrc and put environment variables for HOST and PORT. but I don’t know if this even does anything.


I’m beaten up trying to get simple debugging working. feels almost not worth it. can someone help.

1 Like

If you must cross-post questions for help you could mention it in both places so that you save people the effort in case it gets answered at the other location.