Configure JDTLS to run with specific Java version #1893
Unanswered
fancywriter
asked this question in
Q&A
Replies: 1 comment
-
I was also looking for a way to do this, but it seems the only reasonable option is to use a custom script:
#!/bin/sh
export JAVA_HOME="/path/to/java/21"
exec /full/path/to/mason/bin/jdtls "$@"
/path/to/jdtls/script.sh \
--jvm-arg=-javaagent:/path/to/lombok/lombok.jar \
-configuration /path/to/config/folder \
-data /path/to/workspace I am using nvim-jdtls with lazyvim and this is my actual configuration return {
{
"mfussenegger/nvim-jdtls",
opts = {
cmd = (function()
-- Use vim.fn.expand to expand ~ in JAVA_HOME path
vim.env.JAVA_HOME = vim.fn.expand("~/.asdf/installs/java/adoptopenjdk-21.0.6+7.0.LTS/")
local jdtls_bin = vim.fn.stdpath("data") .. "/mason/bin/jdtls"
local jdtls_pkg = vim.fn.stdpath("data") .. "/mason/packages/jdtls"
local workspace = vim.fn.stdpath("cache") .. "/nvim/jdtls/workspace"
-- Determine platform config folder
local uv = vim.uv or vim.loop
local os_name = uv.os_uname().sysname
local config_folder = "config_linux"
if os_name == "Darwin" then
config_folder = "config_mac"
elseif os_name == "Windows_NT" then
config_folder = "config_win"
end
local cmd = {
jdtls_bin,
"--jvm-arg=-javaagent:" .. jdtls_pkg .. "/lombok.jar",
"-configuration",
jdtls_pkg .. "/" .. config_folder,
"-data",
workspace,
}
-- Notify the full command for debugging
vim.schedule(function()
vim.notify(
"Starting jdtls with command:\n" .. table.concat(cmd, " "),
vim.log.levels.INFO,
{ title = "jdtls cmd" }
)
end)
return cmd
end)(),
},
},
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I am working on some legacy projects. Typical in Java world. I have to work on Java-17 and Java-8 code base (I know it could be worse like Java-6 or even Java-5, very typical).
This is what my JAVA_HOME is configured in the project, the project is built with gradle (but should be similar with Maven or any other tool) and it requires that older java version, it won't work with 21 or 23.
However, JDTLS requires at least Java-21 and fails to work with Java-17.
How can I configure Mason to use (I can even hardcode path to java there) to use specific JRE only for JDTLS (but use JAVA_HOME elsewhere, like for running gradle/maven or code linters from other nvim plugins) ?
I use LazyVIM.
I tried to create
~/.config/nvim/lua/plugins/jdtls.lua
But I see it still tries to use Java-17, completely ignores all of this. Because it's installed by mason... how to configure mason properly for this?
I just want to configure it once and forget forever (or until it stop work under <=Java-23 for instance, far future I expect).
Beta Was this translation helpful? Give feedback.
All reactions