You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Help needed: 'The import java.... cannot be resolved' #328
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.
This would not scan the system to find the available JDKs. So you have to have JDK registered manually as follows. You will get such errors when JDK version defined in gradle not found in the config.
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".
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
Activity
s1n7ax commentedon Dec 3, 2024
This would not scan the system to find the available JDKs. So you have to have JDK registered manually as follows. You will get such errors when JDK version defined in gradle not found in the config.
https://github.com/nvim-java/nvim-java?tab=readme-ov-file#clamp-how-to-use-jdk-xx-version
For maven, you might need some modifications:
https://github.com/nvim-java/nvim-java/wiki/Troubleshooting#no_entry-lsp-doesnt-work-on-maven-projects
AchoVasilev commentedon Dec 3, 2024
I added this to my config:
I also tried this path "/usr/lib/jvm/java-17-openjdk-amd64/bin/java", but the result is the same.
obarbier commentedon 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 commentedon 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 commentedon 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 commentedon Dec 3, 2024
Tried it, but still the same error in the logs.
AchoVasilev commentedon Dec 4, 2024
I added
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 commentedon 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 commentedon Dec 5, 2024
From the nvim-java-core.log I get
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 commentedon 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 commentedon Jan 20, 2025
@mv-stns https://stackoverflow.com/a/54535301/6202210 Try this. You could use neoconf to have project local jdtls settings. If this works you could add it to tips and tricks in wiki
mv-stns commentedon Feb 5, 2025
What about packages? im not using any dep managers. unfortunately still not working.
mv-stns commentedon Feb 5, 2025
Ive clean installed into a empty nvim project and i get this error, i cant find ANY related issues anywhere