GeezerVison is showing github.com — Help needed: 'The import java.... cannot be resolved' · Issue #328 · nvim-java/nvim-java
Help needed: 'The import java.... cannot be resolved' #328DescriptionHello.
I just installed the plugin, following the LazyVim guide and when I use it on a work project, that uses microservices and Spring Boot I get the errors "import java.etc.etc cannot be resolved" or @service "Service cannot be resolved to a type". The project uses Java 17 and Gradle. I tried with 2 other projects that I downloaded from the internet, both of them were Spring Boot applications and one was Maven and the other Gradle. When I opened both projects, the lsp loaded and there were no errors and autocompletion was working. I am guessing it is some with the work project may be, but I am not sure what to do. Hope to get some help.
I am on Ubuntu 24.04 and nvim 0.9.5
Best regards. Activitys1n7ax commented on Dec 3, 2024 AchoVasilev commented on Dec 3, 2024 I added this to my config:
lspconfig.jdtls.setup({
settings = {
java = {
configuration = {
runtimes = {
{
name = "Java-17",
path = "/usr/bin/java",
default = true,
},
},
},
},
},
})
I also tried this path "/usr/lib/jvm/java-17-openjdk-amd64/bin/java", but the result is the same. obarbier commented on Dec 3, 2024 have the same issue. i have 2 jdk (8 and 17) but seem like only 8 is loading up. - would still love some help on this @s1n7ax
Regarding you config one thing I have to say is you should point to the jdk path and not the java executable. i.e. /usr/lib/jvm/java-17-openjdk-amd64/
Also check the LspLog, I am able to solve a lot of my issue from the ERROR log message @AchoVasilev AchoVasilev commented on Dec 3, 2024 This is the LspLog
errors.zip
It is a pretty long file with errors during build. Also had to change the name to "JavaSE-17". There is a bit of autocompletion and intelli-sense, but I still get the "Import cannot be resolved". obarbier commented on Dec 3, 2024 given that it log say Failed to build workspace. I would delete workspace folder and retry. it is usually under ~/.cache/nvim/jdtls/workspaces/ AchoVasilev commented on Dec 3, 2024 Tried it, but still the same error in the logs. AchoVasilev commented on Dec 4, 2024 I added
annotationProcessing = {
enabled = true
}
and the error log is now different
errors.zip
this is an example project structure:
(module)
├── service1 (module)
│ ├── src
│ │
│ └── build.gradle
├── service2 (module)
│ ├── src
│ │
│ └── build.gradle
│
└── build.gradle
└── settings.gradle obarbier commented on Dec 4, 2024 I do get similar error i just learn to disregard them. I am not familiar with gradle as i mostly use maven. not if some of the issue you are facing are related to this.
Also one thing to note is that you are using multi-module, I haven't found a good flow that work for me. i sort of fix this by using vim.lsp.buf.add_workspace_folder to add all the module folder and that usually work better AchoVasilev commented on Dec 5, 2024 From the nvim-java-core.log I get
[INFO Thu 05 Dec 2024 15:54:12 EET] ...share/nvim/lazy/nvim-java-dap/lua/java-dap/api/setup.lua:80: creating dap configuration for java
[DEBUG Thu 05 Dec 2024 15:54:12 EET] ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:62: sending LSP request: workspace/executeCommand
[DEBUG Thu 05 Dec 2024 15:54:20 EET] ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:69: workspace/executeCommand success!
So I am guessing that it finds the module correctly? I also cloned this repo https://github.com/jghoman/gradle-subprojects/tree/master and it worked out of the box, without any errors. mv-stns commented on Jan 20, 2025 Wait but what should i do when i dont use build tools like maven or gradle? Packages seem to not work for me... since libraries can be found

s1n7ax commented on Jan 20, 2025 mv-stns commented on Feb 5, 2025 What about packages? im not using any dep managers. unfortunately still not working. mv-stns commented on Feb 5, 2025 Ive clean installed into a empty nvim project and i get this error, i cant find ANY related issues anywhere

MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|