Created
March 4, 2025 01:34
-
-
Save gmr458/d44da7d042b1285a3826e093aea3364b to your computer and use it in GitHub Desktop.
Simple config for nvim-jdtls on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- this file should be located inside C:\Users\<YOUR-USER>\AppData\Local\nvim\ftplugin | |
| -- i use mason to install jdtls, is easier for | |
| -- me to use mason than download, extract | |
| -- a put jdtls somewhere in my file system | |
| -- mason provides a function to get the path of the | |
| -- language server you installed with mason itself | |
| -- | |
| -- on windows is something like this: | |
| -- | |
| -- C:\Users\<YOUR-USER>\AppData\Local\nvim-data\mason\packages\jdtls | |
| -- | |
| -- i find this useful if i want my config to work in other operative systems | |
| local mason = require 'mason-registry' | |
| local jdtls_path = mason.get_package('jdtls'):get_install_path() | |
| -- if you don't want to use mason, you can delete the line | |
| -- to require mason-registry, copy the path where you have | |
| -- jdtls in your system and paste that inside a string a assign it | |
| -- to the variable jdtls_path | |
| -- this is a path that jdtls needs to work, see the asterisk, vim.fn.glob asterisk here | |
| -- will replace that asterisk with the version installed | | |
| local equinox_launcher_path = vim.fn.glob(jdtls_path .. '/plugins/org.eclipse.equinox.launcher_*.jar') | |
| -- ^ | |
| -- asterisk here | |
| -- this is easy to understand | |
| local system = 'linux' | |
| if vim.fn.has 'win32' then | |
| system = 'win' | |
| elseif vim.fn.has 'mac' then | |
| system = 'mac' | |
| end | |
| local config_path = vim.fn.glob(jdtls_path .. '/config_' .. system) | |
| -- we need this path for lombok support | |
| local lombok_path = jdtls_path .. '/lombok.jar' | |
| local jdtls = require 'jdtls' | |
| -- we can get the value of the env var JAVA_HOME using os.getenv | |
| local java_home = os.getenv('JAVA_HOME') | |
| local config = { | |
| cmd = { | |
| java_home .. '/bin/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', | |
| '-Xmx1g', | |
| '--add-modules=ALL-SYSTEM', | |
| '--add-opens', | |
| 'java.base/java.util=ALL-UNNAMED', | |
| '--add-opens', | |
| 'java.base/java.lang=ALL-UNNAMED', | |
| '-javaagent:' .. lombok_path, | |
| '-jar', | |
| equinox_launcher_path, | |
| '-configuration', | |
| config_path, | |
| '-data', | |
| vim.fn.stdpath 'cache' | |
| .. '/jdtls/' | |
| .. vim.fn.fnamemodify(vim.fn.getcwd(), ':t'), | |
| }, | |
| root_dir = vim.fs.root(0, {".git", "mvnw", "gradlew"}), | |
| -- here require your own on_attach function | |
| -- in my config inside the on_attach function | |
| -- i setup some keymaps and other config | |
| -- i don't know your config, you can omit this line | |
| -- if you want | |
| on_attach = require('path.to.my.on_attach.function').on_attach, | |
| -- 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 | |
| -- for a list of options, there is not issue if you let this empty | |
| settings = { | |
| java = { | |
| }, | |
| }, | |
| -- there is not issue if you let this empty | |
| init_options = { | |
| bundles = { | |
| } | |
| } | |
| } | |
| jdtls.start_or_attach(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment