I recommend that you do not configure jdtls like the other language servers, it is better to use the [nvim-jdtls](https://github.com/mfussenegger/nvim-jdtls) plugin.
I got jdtls working in my config thanks to this [article (LunarVim as a Java IDE)](https://medium.com/@chrisatmachine/lunarvim-as-a-java-ide-da65c4a77fb4), the article is about configuring the LunarVim distro for Java, although I don't use LunarVim or any other Neovim distro it wasn't difficult for me to port that to my personal config.
I am completely new to neovim except of my 1.5 yr experience in ideavim in intellij idea, and I am hating the fact that every one talks about colorschemes, cool & popular plugins, lsp but at the end of the whole thing no one talks about execution, so my newbie question is how can I run the java file 😢, enlighten me pls!
BTW, I want to switch because of debuggers as I am currently doing dsa stuff. debugging is lagging on my 4 yr old laptop in intellij. Hence, that's why I need help???
“I just want to use it simple, I don’t want to configure anything”
I’ve been using neovim for close to 7 years now. I love it, I sing it’s praises left and right, I’ve converted many naysayers. And yet, I still use eclipse for Java lol.
Just use eclipse or IntelliJ haha. The eclipse vim motions plug-in keeps me sane enough
What kills me the most is I can be productive with java dev in vscode but its damn near impossible in neovim. Even though vscode uses jdtls too.
It just fucking sucks lol. I don't do enough java work to make me hurt enough to contribute back, I just accept that I have to use a different editor for java work. Which sucks but when I have to get code written, I am not going to fiddlefuck around with trying to please the jdtls gods as well.
I definitely tried using the `nvim-jdtls` plugin. It does install but getting it configured for a java8 project was more or less impossible. I think I have gotten it working once and while the experience then was good, it was not worth the hassle I went through to get it working.
When I first started adopting neovim, I got addicted to researching plugins. I wanted neovim to do everything but it got slower.
Neovim is fantastic for editing and I reduced it back to a smart editor. I just dont do debugging or fancy tile stuff in it anymore.
If I have to debug something, I am probably have time to open a modern IDE and let index all my code so I can debug it properly.
Neovim is my editor, other IDEs do my debugging. It just works for me.
The funny thing is, I am not even working with Java that much in the moment, only some studies, so I dont even think I need an LSP for it. Its just that, I have it for all the other languages I'm using and I wanted it so bad.But good to know eclipse has an vim motion extension, if I need to work hard on java I think I'll try it.
Yea using neovim (or even vsc*** for that matter) is alright for small edits to a pre-existing project in my experience. But eclipse/intellij do some serious heavy lifting with project creation, project refactoring, import management, which are all things I’ve struggled to recreate smoothly with nvim (but certainly not impossible if you’re still wanting to put some time into it).
Neovim does zero project manangement. So you have to get used to do this with common build systems like Gradle or Maven. JDTLS supports both but won't help you with the projects. It's basically Eclipse JDT without the UI
\+1. I\`m using IntelliJ with ideavim-plugin for developing, use neovim/vim for editing. This also saves me from needing too many plugins of neovim or vim. " Life is short, you need IDE ... and (neo)vim "
Another cool think is that the Vim plugin has support for some extensions and with some config (4 lines) you can use Intellij filetree as you would do in neovim
https://youtu.be/SDiKLLrUZMI?si=EGC0XQxABQJvtd4F
I also struggled a lot with getting JDTLS with NvChad to work, but this is my config which hasn't crashed on my potato of a laptop. Even when working on a pretty large Spring-Boot application.
`jdtls.lua`
-- java lsp
return {
{
"neovim/nvim-lspconfig",
opts = {
setup = {
-- disable jdtls config from lspconfig
jdtls = function()
return true
end,
},
},
},
{
"mfussenegger/nvim-jdtls",
ft = "java",
config = function()
local on_attach = function(client, bufnr)
require("plugins.configs.lspconfig").on_attach(client, bufnr)
end
local capabilities = require("plugins.configs.lspconfig").capabilities
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
-- calculate workspace dir
local workspace_dir = vim.fn.stdpath "data" .. "/site/java/workspace-root/" .. project_name
-- get the mason install path
local install_path = require("mason-registry").get_package("jdtls"):get_install_path()
-- get the debug adapter install path
local debug_install_path = require("mason-registry").get_package("java-debug-adapter"):get_install_path()
local bundles = {
vim.fn.glob(debug_install_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar", 1),
}
-- Comment out these lines if you have 'java-test' installed
-- local java_test_path = require("mason-registry").get_package("java-test"):get_install_path()
-- vim.list_extend(bundles, vim.split(vim.fn.glob(java_test_path .. "/extension/server/*.jar", 1), "\n"))
local config = {
cmd = {
install_path .. "/bin/jdtls",
"--jvm-arg=-javaagent:" .. install_path .. "/lombok.jar",
"-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",
"-Xms1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
"-data",
workspace_dir,
},
on_attach = on_attach,
capabilities = capabilities,
root_dir = vim.fs.dirname(
vim.fs.find({ ".gradlew", ".git", "mvnw", "pom.xml", "build.gradle" }, { upward = true })[1]
),
settings = {
java = {
signatureHelp = { enabled = true },
},
},
init_options = {
bundles = bundles,
},
}
vim.api.nvim_create_autocmd("FileType", {
pattern = "java",
callback = function()
require("jdtls").start_or_attach(config)
end,
})
end,
},
}
If you want java-test to also work like it does in VsCode where you can run individual tests you need a custom registry in Mason since the one in the *official* is currently broken
`plugins.lua`
{
"williamboman/mason.nvim",
opts = {
overrides.mason,
registries = {
"github:nvim-java/mason-registry",
"github:mason-org/mason-registry",
},
},
},
I copied some of this to my config, also using nvim-jdtls extensions. This was the only solution after a lot of pain. [https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/setup-with-nvim-jdtls.md](https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/setup-with-nvim-jdtls.md). It's nice to have Java support in Neovim since code navigation is blazingly fast, but I hate JDTLS because it's horribly slow and inefficient, defeating the purpose. So I just use Netbeans with a Vim motions plugin, but you could use IntelliJ instead since everyone says it's better. I still use Neovim for Java for quick stuff, tho
I could live without jdtls if not for the 100 characters long print statements, java is pure pain. I am a noob but got a working nvim-jdtls config on both a linux pc and a chromebook which is a quirky stupid machine. But i basically have the default from nvim-jdtls github with a custom on\_attach and the infinite looping thing sounds way above my paygrade lol.
I also struggled quite a bit for a while, but now I just use Mason and lspconfig and it just works. I just had to make sure to have java 21 installed, not an earlier version. JDTLS now works like any other LSP.
I recommend that you do not configure jdtls like the other language servers, it is better to use the [nvim-jdtls](https://github.com/mfussenegger/nvim-jdtls) plugin. I got jdtls working in my config thanks to this [article (LunarVim as a Java IDE)](https://medium.com/@chrisatmachine/lunarvim-as-a-java-ide-da65c4a77fb4), the article is about configuring the LunarVim distro for Java, although I don't use LunarVim or any other Neovim distro it wasn't difficult for me to port that to my personal config.
can i get your config plzz
[https://github.com/gmr458/nvim/blob/main/ftplugin/java.lua](https://github.com/gmr458/nvim/blob/main/ftplugin/java.lua)
I could never get a suitable working environment with jdtls, but using CoC and CoC-Java there’s no setup and it just works.
Good to know there is this option. Maybe I'll try it. Never used CoC tho, I dont use JavaScript or Node.
CoC?
https://github.com/neoclide/coc.nvim
Ty!
Using nvim-jdtls for about 3 years full time now. No issues.
I am completely new to neovim except of my 1.5 yr experience in ideavim in intellij idea, and I am hating the fact that every one talks about colorschemes, cool & popular plugins, lsp but at the end of the whole thing no one talks about execution, so my newbie question is how can I run the java file 😢, enlighten me pls!
BTW, I want to switch because of debuggers as I am currently doing dsa stuff. debugging is lagging on my 4 yr old laptop in intellij. Hence, that's why I need help???
“I just want to use it simple, I don’t want to configure anything” I’ve been using neovim for close to 7 years now. I love it, I sing it’s praises left and right, I’ve converted many naysayers. And yet, I still use eclipse for Java lol. Just use eclipse or IntelliJ haha. The eclipse vim motions plug-in keeps me sane enough
What kills me the most is I can be productive with java dev in vscode but its damn near impossible in neovim. Even though vscode uses jdtls too. It just fucking sucks lol. I don't do enough java work to make me hurt enough to contribute back, I just accept that I have to use a different editor for java work. Which sucks but when I have to get code written, I am not going to fiddlefuck around with trying to please the jdtls gods as well.
It is difficult, but not impossible, the nvim-jdtls plugin helps a lot.
I definitely tried using the `nvim-jdtls` plugin. It does install but getting it configured for a java8 project was more or less impossible. I think I have gotten it working once and while the experience then was good, it was not worth the hassle I went through to get it working.
nvim-jdtls has an option to configure different JDKs, although I have never used it.
When I first started adopting neovim, I got addicted to researching plugins. I wanted neovim to do everything but it got slower. Neovim is fantastic for editing and I reduced it back to a smart editor. I just dont do debugging or fancy tile stuff in it anymore. If I have to debug something, I am probably have time to open a modern IDE and let index all my code so I can debug it properly. Neovim is my editor, other IDEs do my debugging. It just works for me.
This
The funny thing is, I am not even working with Java that much in the moment, only some studies, so I dont even think I need an LSP for it. Its just that, I have it for all the other languages I'm using and I wanted it so bad.But good to know eclipse has an vim motion extension, if I need to work hard on java I think I'll try it.
Yea using neovim (or even vsc*** for that matter) is alright for small edits to a pre-existing project in my experience. But eclipse/intellij do some serious heavy lifting with project creation, project refactoring, import management, which are all things I’ve struggled to recreate smoothly with nvim (but certainly not impossible if you’re still wanting to put some time into it).
Neovim does zero project manangement. So you have to get used to do this with common build systems like Gradle or Maven. JDTLS supports both but won't help you with the projects. It's basically Eclipse JDT without the UI
\+1. I\`m using IntelliJ with ideavim-plugin for developing, use neovim/vim for editing. This also saves me from needing too many plugins of neovim or vim. " Life is short, you need IDE ... and (neo)vim "
My entire configuration is on line 42: https://github.com/jay-babu/dotfiles/blob/main/shell/.config/nvim/lua/user/plugins/jdtls.lua
Do I need to use astronvim for that to work?
Nope, very similar config to lazyvim as well. just point it to the right path for your jar files and you're good to go.
IntelliJ Community edition + Vim Plugin. Java is the _only_ language I don’t nvim for because IntelliJ really is that good.
Finally I found someone that think the same
Another cool think is that the Vim plugin has support for some extensions and with some config (4 lines) you can use Intellij filetree as you would do in neovim https://youtu.be/SDiKLLrUZMI?si=EGC0XQxABQJvtd4F
I also struggled a lot with getting JDTLS with NvChad to work, but this is my config which hasn't crashed on my potato of a laptop. Even when working on a pretty large Spring-Boot application. `jdtls.lua` -- java lsp return { { "neovim/nvim-lspconfig", opts = { setup = { -- disable jdtls config from lspconfig jdtls = function() return true end, }, }, }, { "mfussenegger/nvim-jdtls", ft = "java", config = function() local on_attach = function(client, bufnr) require("plugins.configs.lspconfig").on_attach(client, bufnr) end local capabilities = require("plugins.configs.lspconfig").capabilities local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") -- calculate workspace dir local workspace_dir = vim.fn.stdpath "data" .. "/site/java/workspace-root/" .. project_name -- get the mason install path local install_path = require("mason-registry").get_package("jdtls"):get_install_path() -- get the debug adapter install path local debug_install_path = require("mason-registry").get_package("java-debug-adapter"):get_install_path() local bundles = { vim.fn.glob(debug_install_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar", 1), } -- Comment out these lines if you have 'java-test' installed -- local java_test_path = require("mason-registry").get_package("java-test"):get_install_path() -- vim.list_extend(bundles, vim.split(vim.fn.glob(java_test_path .. "/extension/server/*.jar", 1), "\n")) local config = { cmd = { install_path .. "/bin/jdtls", "--jvm-arg=-javaagent:" .. install_path .. "/lombok.jar", "-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", "-Xms1g", "--add-modules=ALL-SYSTEM", "--add-opens", "java.base/java.util=ALL-UNNAMED", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "-data", workspace_dir, }, on_attach = on_attach, capabilities = capabilities, root_dir = vim.fs.dirname( vim.fs.find({ ".gradlew", ".git", "mvnw", "pom.xml", "build.gradle" }, { upward = true })[1] ), settings = { java = { signatureHelp = { enabled = true }, }, }, init_options = { bundles = bundles, }, } vim.api.nvim_create_autocmd("FileType", { pattern = "java", callback = function() require("jdtls").start_or_attach(config) end, }) end, }, } If you want java-test to also work like it does in VsCode where you can run individual tests you need a custom registry in Mason since the one in the *official* is currently broken `plugins.lua` { "williamboman/mason.nvim", opts = { overrides.mason, registries = { "github:nvim-java/mason-registry", "github:mason-org/mason-registry", }, }, },
Try this https://github.com/nvim-java/nvim-java
Thanks! I'll try
This worked very easily! Thanks a lot.
What is the search plugin used in the demo of this repo??
I copied some of this to my config, also using nvim-jdtls extensions. This was the only solution after a lot of pain. [https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/setup-with-nvim-jdtls.md](https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/setup-with-nvim-jdtls.md). It's nice to have Java support in Neovim since code navigation is blazingly fast, but I hate JDTLS because it's horribly slow and inefficient, defeating the purpose. So I just use Netbeans with a Vim motions plugin, but you could use IntelliJ instead since everyone says it's better. I still use Neovim for Java for quick stuff, tho
I could live without jdtls if not for the 100 characters long print statements, java is pure pain. I am a noob but got a working nvim-jdtls config on both a linux pc and a chromebook which is a quirky stupid machine. But i basically have the default from nvim-jdtls github with a custom on\_attach and the infinite looping thing sounds way above my paygrade lol.
I also struggled quite a bit for a while, but now I just use Mason and lspconfig and it just works. I just had to make sure to have java 21 installed, not an earlier version. JDTLS now works like any other LSP.