GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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' #328

New issue
Copy link
New issue
Copy link
Open
Open
Help needed: 'The import java.... cannot be resolved'#328
Copy link

Description

@AchoVasilev
AchoVasilev
opened on Dec 2, 2024
Issue body actions

Hello.

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.

Activity

  1. s1n7ax commented on Dec 3, 2024

    @s1n7ax
    s1n7ax
    on Dec 3, 2024
    Member
    More actions

    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

  2. AchoVasilev commented on Dec 3, 2024

    @AchoVasilev
    AchoVasilev
    on Dec 3, 2024
    Author
    More actions

    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.

  3. obarbier commented on Dec 3, 2024

    @obarbier
    obarbier
    on Dec 3, 2024
    More actions

    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

  4. AchoVasilev commented on Dec 3, 2024

    @AchoVasilev
    AchoVasilev
    on Dec 3, 2024
    Author
    More actions

    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".

  5. obarbier commented on Dec 3, 2024

    @obarbier
    obarbier
    on Dec 3, 2024
    More actions

    given that it log say Failed to build workspace. I would delete workspace folder and retry. it is usually under ~/.cache/nvim/jdtls/workspaces/

  6. AchoVasilev commented on Dec 3, 2024

    @AchoVasilev
    AchoVasilev
    on Dec 3, 2024
    Author
    More actions

    Tried it, but still the same error in the logs.

  7. AchoVasilev commented on Dec 4, 2024

    @AchoVasilev
    AchoVasilev
    on Dec 4, 2024
    Author
    More actions

    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

  8. obarbier commented on Dec 4, 2024

    @obarbier
    obarbier
    on Dec 4, 2024
    More actions

    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

  9. AchoVasilev commented on Dec 5, 2024

    @AchoVasilev
    AchoVasilev
    on Dec 5, 2024
    Author
    More actions

    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.

  10. mv-stns commented on Jan 20, 2025

    @mv-stns
    mv-stns
    on Jan 20, 2025
    More actions

    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

    Image

  11. s1n7ax commented on Jan 20, 2025

    @s1n7ax
    s1n7ax
    on Jan 20, 2025
    Member
    More actions

    @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

  12. mv-stns commented on Feb 5, 2025

    @mv-stns
    mv-stns
    on Feb 5, 2025
    More actions

    What about packages? im not using any dep managers. unfortunately still not working.

  13. mv-stns commented on Feb 5, 2025

    @mv-stns
    mv-stns
    on Feb 5, 2025
    More actions

    Ive clean installed into a empty nvim project and i get this error, i cant find ANY related issues anywhere

    Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.