1. Installjdtls from the mason using :MasonInstall jdtls or :Mason
  2. Then add jdtls in list of lsp’s :
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'ts_ls', 'gopls', 'jdtls' }

[–more–]

  1. If your are working with just basic java files, Initialize git in you working directory and create .project file.
git init
touch .project
  1. Now, open any java file and check if jdtls lsp is attached using :LspInfo, check for this:
- 1 client(s) attached to this buffer
- Client: `jdtls` (id: 1, bufnr: [1])

if bufnr is > 0 then, it worked.

Reference: ChatGPT