Blog

It's minimal, but I'm posting things.

Combining the asdf version manager with the Java LSP in Vim

I manage my runtime versions using asdf.

Running Java LSPs like eclipse-jdt-ls in Vim becomes painful when using version managers like asdf.
You need to override the default command provided by the vim-lsp-settings project.

Specifically, the LSP needs your to explicitely export JAVA_HOME and add your Java runtime executable to the PATH env variable to function.

A useful helper Function

This reusable s:SafeLspCmd helper validates the executable and constructs the command list, supporting environment variable injection via a prefix list.
Using this helper prevents seeing error messages if the executable is not found on your system.

function! s:SafeLspCmd(executable, script_path, ...) abort
  if !executable(a:executable) | return [] | endif
  if !empty(a:script_path) && !filereadable(a:script_path) | return [] | endif
  
  if a:0 >= 1 && type(a:1) == v:t_list
    let l:prefix = a:1
    let l:rest = a:000[1:]
  else
    let l:prefix = []
    let l:rest = a:000
  endif
  return [a:executable] + l:prefix + [a:script_path] + l:rest
endfunction

The LSP Configuration

Use the helper with env to inject JAVA_HOME and PATH before launching eclipse-jdt-ls.

let g:lsp_settings = {
 \ 'eclipse-jdt-ls': {
 \    'cmd': {server_info->s:SafeLspCmd(
 \            'env',
 \            lsp_settings#exec_path('eclipse-jdt-ls') . 'eclipse-jdt-ls',
 \            ['JAVA_HOME=' . expand('~/.asdf/installs/java/openjdk-21'),
 \             'PATH=' . expand('~/.asdf/installs/java/openjdk-21/bin') . ':' . $PATH])}
 \   }
 \ }

Conclusion

Now the Java LSP should start properly; you can check with the :LspStatus command.


Published on 2026-02-15T12:24:25.59468Z
Last updated on 2026-02-15T12:24:25.594979Z