Hello guys, i'm trying to add nvim-jdtls plugin using launch.nvim. My nvim-jdtls.lua looks like this:
local M = {
'mfussenegger/nvim-jdtls',
ft = { "java" }, -- Enable only on .java file extensions
}
function M.config()
vim.notify("Loading jdtls setup...")
-- JDTLS (Java LSP) configuration
local jdtls = require "jdtls"
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = vim.env.HOME .. "/code/workspace/" .. project_name
-- Needed for debugging
local bundles = {
vim.fn.glob(
vim.env.HOME .. "/.local/share/nvim/mason/share/java-debug-adapter/com.microsoft.java.debug.plugin.jar"
),
}
-- Needed for running/debugging unit tests
vim.list_extend(
bundles,
vim.split(vim.fn.glob(vim.env.HOME .. "/.local/share/nvim/mason/share/java-test/*.jar", 1), "\n")
)
-- See `:help vim.lsp.start_client` for an overview of the supported `config` options.
local config = {
-- The command that starts the language server
-- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
cmd = {
"java",
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Dosgi.bundles.defaultStartLevel=4",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
"-Dlog.protocol=true",
"-Dlog.level=ALL",
"-javaagent:" .. vim.env.HOME .. "/.local/share/nvim/mason/share/jdtls/lombok.jar",
"-Xmx4g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
-- Eclipse jdtls location
"-jar",
vim.env.HOME .. "/.local/share/nvim/mason/share/jdtls/plugins/org.eclipse.equinox.launcher.jar",
-- TODO Update this to point to the correct jdtls subdirectory for your OS (config_linux, config_mac, config_win, etc)
"-configuration",
vim.env.HOME .. "/.local/share/nvim/mason/packages/jdtls/config_linux",
"-data",
workspace_dir,
},
-- This is the default if not provided, you can remove it. Or adjust as needed.
-- One dedicated LSP server & client will be started per unique root_dir
root_dir = require("jdtls.setup").find_root { ".git", "mvnw", "pom.xml", "build.gradle" },
-- Here you can configure eclipse.jdt.ls specific settings
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
settings = {
java = {
-- TODO Replace this with the absolute path to your main java version (JDK 17 or higher)
home = "/usr/lib/jvm/java-17-amazon-corretto",
eclipse = {
downloadSources = true,
},
configuration = {
updateBuildConfiguration = "interactive",
-- TODO Update this by adding any runtimes that you need to support your Java projects and removing any that you don't have installed
-- The runtime name parameters need to match specific Java execution environments. See https://github.com/tamago324/nlsp-settings.nvim/blob/2a52e793d4f293c0e1d61ee5794e3ff62bfbbb5d/schemas/_generated/jdtls.json#L317-L334
runtimes = {
{
name = "JavaSE-1.8",
path = "/usr/lib/jvm/java-8-amazon-corretto",
},
{
name = "JavaSE-11",
path = "/usr/lib/jvm/java-11-amazon-corretto",
},
{
name = "JavaSE-17",
path = "/usr/lib/jvm/java-17-amazon-corretto",
},
},
},
maven = {
downloadSources = true,
},
implementationsCodeLens = {
enabled = true,
},
referencesCodeLens = {
enabled = true,
},
references = {
includeDecompiledSources = true,
},
signatureHelp = { enabled = true },
format = {
enabled = true,
-- Formatting works by default, but you can refer to a specific file/URL if you choose
-- settings = {
-- url = "https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml",
-- profile = "GoogleStyle",
-- },
},
},
completion = {
favoriteStaticMembers = {
"org.hamcrest.MatcherAssert.assertThat",
"org.hamcrest.Matchers.*",
"org.hamcrest.CoreMatchers.*",
"org.junit.jupiter.api.Assertions.*",
"java.util.Objects.requireNonNull",
"java.util.Objects.requireNonNullElse",
"org.mockito.Mockito.*",
},
importOrder = {
"java",
"javax",
"com",
"org",
},
},
extendedClientCapabilities = jdtls.extendedClientCapabilities,
sources = {
organizeImports = {
starThreshold = 9999,
staticStarThreshold = 9999,
},
},
codeGeneration = {
toString = {
template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}",
},
useBlocks = true,
},
},
-- Needed for auto-completion with method signatures and placeholders
capabilities = require("cmp_nvim_lsp").default_capabilities(),
flags = {
allow_incremental_sync = true,
},
init_options = {
-- References the bundles defined above to support Debugging and Unit Testing
bundles = bundles,
},
}
-- Needed for debugging
config["on_attach"] = function(client, bufnr)
jdtls.setup_dap { hotcodereplace = "auto" }
require("jdtls.dap").setup_dap_main_class_configs()
end
-- This starts a new client & server, or attaches to an existing client & server based on the `root_dir`.
jdtls.start_or_attach(config)
end
return M
When I open a java file i got the snippets and the following errors:
[ERROR][2024-08-04 20:22:39] .../vim/lsp/rpc.lua:770 "rpc" "java" "stderr" "WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector\n"
[ERROR][2024-08-04 20:22:39] .../vim/lsp/rpc.lua:770 "rpc" "java" "stderr" "Aug 04, 2024 8:22:39 PM org.apache.aries.spifly.BaseActivator log\nINFO: Registered provider ch.qos.logback.classic.servlet.LogbackServletContainerInitializer of service jakarta.servlet.ServletContainerInitializer in bundle ch.qos.logback.classic\n"
[ERROR][2024-08-04 20:22:39] .../vim/lsp/rpc.lua:770 "rpc" "java" "stderr" "Aug 04, 2024 8:22:39 PM org.apache.aries.spifly.BaseActivator log\nINFO: Registered provider ch.qos.logback.classic.spi.LogbackServiceProvider of service org.slf4j.spi.SLF4JServiceProvider in bundle ch.qos.logback.classic\n"
[ERROR][2024-08-04 20:22:41] ...lsp/handlers.lua:623 "Aug 4, 2024, 8:22:41 PM Empty bundle location"
[ERROR][2024-08-04 20:22:41] ...lsp/handlers.lua:623 "Aug 4, 2024, 8:22:41 PM Empty bundle location"
[WARN][2024-08-04 20:22:41] ...lsp/handlers.lua:135 "The language server jdtls triggers a registerCapability handler for workspace/didChangeWorkspaceFolders despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2024-08-04 20:22:42] ...lsp/handlers.lua:623 "Aug 4, 2024, 8:22:42 PM Command _java.reloadBundles.command not supported on client"
[ERROR][2024-08-04 20:22:47] .../vim/lsp/rpc.lua:770 "rpc" "java" "stderr" "Aug 04, 2024 8:22:47 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation\nWARNING: Unmatched cancel notification for request id 19\n"
[ERROR][2024-08-04 20:23:34] .../vim/lsp/rpc.lua:770 "rpc" "java" "stderr" "Aug 04, 2024 8:23:34 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation\nWARNING: Unmatched cancel notification for request id 33\n"
[ERROR][2024-08-04 20:23:48] .../vim/lsp/rpc.lua:770 "rpc" "java" "stderr" "Aug 04, 2024 8:23:48 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation\nWARNING: Unmatched cancel notification for request id 57\n"
[ERROR][2024-08-04 20:23:51] .../vim/lsp/rpc.lua:770 "rpc" "java" "stderr" "Aug 04, 2024 8:23:51 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation\nWARNING: Unmatched cancel notification for request id 68\n"
I tried add a ftplugin folder with a java.lua inside but a got the same error
In my work we using intellij but i would to migrate to nvim, sorry for my english haha
Hello guys, i'm trying to add nvim-jdtls plugin using launch.nvim. My nvim-jdtls.lua looks like this:
When I open a java file i got the snippets and the following errors:
I tried add a ftplugin folder with a java.lua inside but a got the same error In my work we using intellij but i would to migrate to nvim, sorry for my english haha