@@ -20,7 +20,14 @@ function M.get_cmd(opts)
2020 return function (dispatchers , config )
2121 local cmd = M .get_jvm_args (opts ):concat (M .get_jar_args ())
2222
23- M .validate_java_version (config .cmd_env )
23+ -- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not
24+ -- working on Windows. So just lanching 'java' will result in executing the
25+ -- system java. So as a workaround, we use the absolute path to java instead
26+ -- So following check is not needed when we have auto_install set to true
27+ -- @see https://github.com/neovim/neovim/issues/36818
28+ if not conf .jdk .auto_install then
29+ M .validate_java_version (config .cmd_env )
30+ end
2431
2532 log .debug (' Starting jdtls with cmd' , cmd )
2633
4047function M .get_jvm_args (opts )
4148 local jdtls_config = path .join (jdtls_root , system .get_config_suffix ())
4249
50+ local java_exe = ' java'
51+
52+ -- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not
53+ -- working on Windows. So we are using the absolute path to java instead
54+ -- @see https://github.com/neovim/neovim/issues/36818
55+ if conf .jdk .auto_install then
56+ local jdk_root = Manager :get_install_dir (' openjdk' , conf .jdk .version )
57+ local java_home
58+ if system .get_os () == ' mac' then
59+ java_home = vim .fn .glob (path .join (jdk_root , ' jdk-*' , ' Contents' , ' Home' ))
60+ else
61+ java_home = vim .fn .glob (path .join (jdk_root , ' jdk-*' ))
62+ end
63+
64+ java_exe = path .join (java_home , ' bin' , ' java' )
65+ end
66+
4367 local jvm_args = List :new ({
44- ' java ' ,
68+ java_exe ,
4569 ' -Declipse.application=org.eclipse.jdt.ls.core.id1' ,
4670 ' -Dosgi.bundles.defaultStartLevel=4' ,
4771 ' -Declipse.product=org.eclipse.jdt.ls.core.product' ,
0 commit comments