-
-
Notifications
You must be signed in to change notification settings - Fork 44
DAP support java
Zeioth edited this page Aug 9, 2023
·
7 revisions
Nothing special needs to be done for java.
Please note that this section has nothing to do with compiler.nvim. I'm documenting this to make your life easier. To debug java with DAP you have to:
- Install
java-debug-adapterandjava-testusing Mason. - Install the system dependency
jdtls. - Then inside the root directory of your nvim config directory you must create
/ftplugin/java.luaand paste this
-- HOW TO CONFIGURE THE JAVA DEBUGGER
-- -------------------------------------------------------------------------
-- https://github.com/mfussenegger/nvim-jdtls#configuration-quickstart
-- -------------------------------------------------------------------------
--
-- YOU MUST:
-- * Install the system dependency 'jdtls' in your operative system.
-- * Set the right path of your jdtls executable below in 'cmd'.
--
-- IF STILL FAILS CHECK:
-- * You have installed 'java-debug-adapter' on mason.
-- * The path of "bundles" if correct.
local config = {
cmd = {'/usr/bin/jdtls'},
root_dir = vim.fs.dirname(vim.fs.find({'gradlew', '.git', 'mvnw'}, { upward = true })[1]),
init_options = {
bundles = {
vim.fn.glob(vim.fn.stdpath('data')..'/mason/packages/java-test/extension/server/*.jar', true ),
vim.fn.glob(vim.fn.stdpath('data')..'/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar', true ),
}
}
}
require('jdtls').start_or_attach(config)
-- Give enough time for jdt to fully load the project, or it will fail with
-- "No LSP client found"
local timer = 2500
local test = nil
for i = 0, 12, 1 do
vim.defer_fn(function() test = require('jdtls.dap').setup_dap_main_class_configs()
print(test)
end, timer)
timer = timer + 2500
endAll there is left to do is adding a breakpoint to your code, and run :DapContinue

- As you can see, the java DAP debugger is trickier to configure than the other debuggers, as it has its own way to do it. Hopefully the situation will change in the future.
- If you find any issue while configuring DAP, run
:DapSetLogLevel traceand:DapShowLogto find the reason.