Skip to content

The import X cannot be resolved #122

Closed
Closed

Description

@sedax90

Relevance Confirmation

  • I confirmed that this is not an issue with the Eclipse JDT Language Server itself

What happened?

I added a dependency to my build.gradle:

implementation 'commons-net:commons-net:3.12.0'

I would have expected it to be resolved within my file, but importing any of the dependencies returns: The import org.apache.commons.net cannot be resolved (Java 268435846)

Image

Opening VScode resolves the dependency correctly; in fact, with ./gradlew build the project starts correctly.

What did you expect to happen?

It should automatically resolve dependencies once they are entered and built.

Environment

Zed: 0.210.4 428ef505984eb7dd6096cbe6ff4e07f293075d0d
Platform: Ubuntu 25.10
Java:
openjdk 23 2024-09-17
OpenJDK Runtime Environment Corretto-23.0.0.37.1 (build 23+37-FR)
OpenJDK 64-Bit Server VM Corretto-23.0.0.37.1 (build 23+37-FR, mixed mode, sharing)

Activity

  1. added theissue type on Nov 5, 2025
  2. tartarughina commented on Nov 5, 2025

    @tartarughina
    Collaborator

    For now you should be able to fix this issue by recreating the .classpath file and the .factorypath one. I need to take a look at how the current VS Code extension triggers automatically such refresh for imports. Maybe it's trivial.

  3. sedax90 commented on Nov 5, 2025

    @sedax90
    Author

    I've remove the app/.classpath file but now I've lost autocomplete, errors, etc.

  4. tartarughina commented on Nov 5, 2025

    @tartarughina
    Collaborator

    You should recreate it, not delete it

  5. sedax90 commented on Nov 5, 2025

    @sedax90
    Author

    .classpath is an Eclipse file, how can I recreate it?

    EDIT
    Ok I've imported the 'eclipse' plugin in build.gradle and launched ./gradlew eclipse, now all it works. I don't think this is the correct procedure, however.

  6. tartarughina commented on Nov 5, 2025

    @tartarughina
    Collaborator

    Try with ./gradlew dependencies --configuration compileClasspath

  7. sedax90 commented on Nov 5, 2025

    @sedax90
    Author

    Try with ./gradlew dependencies --configuration compileClasspath

    my build.gradle does not have a compileClasspath config, so it return error.

    I don't known if this issue can be compared with Vscode because I've tried to reopen the project with it, clean the java workspace with the vscode command and none of this actions have recreated it or modified the .classpath.
    I can do more tests if you want, actually I don't known how this plugin works but I suspect that it should provide some automations if it depends to some extra projects dependencies like "eclipse".

  8. sedax90 commented on Nov 7, 2025

    @sedax90
    Author

    This is issue is still present also with classes manually created in the project externally, example with vscode:

    Image
  9. tartarughina commented on Nov 8, 2025

    @tartarughina
    Collaborator

    Including the eclipse plugin might indeed be the solution. The language server we are using, as well as VSCode, is eclipse.jdt.ls

  10. sedax90 commented on Nov 8, 2025

    @sedax90
    Author

    Including the eclipse plugin might indeed be the solution. The language server we are using, as well as VSCode, is eclipse.jdt.ls

    I don't know because I've included the eclipse plugin in my project and I've tried to regenerate multiple times the classpath file without results. I can do some tests if you have some actions to try.

  11. tartarughina commented on Nov 8, 2025

    @tartarughina
    Collaborator

    You did the following

    Ok I've imported the 'eclipse' plugin in build.gradle and launched ./gradlew eclipse, now all it works. I don't think this is the correct procedure, however.

    After that you got correct suggestions and class information or did you have to do something additional?

  12. sedax90 commented on Nov 10, 2025

    @sedax90
    Author

    You did the following

    Ok I've imported the 'eclipse' plugin in build.gradle and launched ./gradlew eclipse, now all it works. I don't think this is the correct procedure, however.

    After that you got correct suggestions and class information or did you have to do something additional?

    I did some tests and the only thing that worked was to delete the .classpath, .projects and .settings files from app. After doing this by running ./gradlew eclipse the paths worked without any problems.

  13. tartarughina commented on Nov 10, 2025

    @tartarughina
    Collaborator

    Thanks for the details.
    Reading about the topic on the language server repo, it should be able to understand the project type and trigger an automatic creation of the files it needs.

    This import behavior can be set by providing initialization options to the server, you have an example of it in our Advanced configuration.

    You might have the feature already enabled, and, as you had highlighted, this might cause unintended results.
    I assume your class paths contained a relative path rather than an absolute one, causing the language server to fail obtaining
    the required info.

    Based on this reddit post it might actually be better to include in the project settings the eclipse plugin and invoking it manually.

    In the effort of making this extension more polished, we have as of now a single option, provide a command or task to run either gradle eclipse or mvn eclipse:eclipse.

    Updating a file within the project is not allowed as of now. Ideally otherwise, we would also update the project file to consume the eclipse plugin.

  14. tartarughina commented on Dec 6, 2025

    @tartarughina
    Collaborator

    @sedax90 Take a look at #146. The same initialization options discussed there should resolve the issue you're facing.
    If that works for you, I’ll prioritize adding proper documentation and an easy way to enable these options, instead of implementing tasks to manually run Eclipse-specific commands.

  15. sedax90 commented on Dec 11, 2025

    @sedax90
    Author

    @sedax90 Take a look at #146. The same initialization options discussed there should resolve the issue you're facing. If that works for you, I’ll prioritize adding proper documentation and an easy way to enable these options, instead of implementing tasks to manually run Eclipse-specific commands.

    I've added:

      "lsp": {
        "jdtls": {
          "initialization_options": {
            "settings": {
              "java": {
                "format": {
                  "enabled": true,
                  "settings": {
                    "profile": "GoogleStyle",
                    "url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml"
                  }
                },
                "import": {
                  "gradle": {
                    "enabled": true
                  },
                  "maven": {
                    "enabled": true
                  },
                  "exclusions": [
                    "**/.metadata/**",
                    "**/archetype-resources/**",
                    "**/META-INF/maven/**"
                  ]
                }
              }
            }
          }
        }
      }
    

    but I've some errors anyway:

    Image
  16. sedax90 commented on Feb 26, 2026

    @sedax90
    Author

    there's an estimation time when this issue will be resolved?

  17. tartarughina commented on Feb 26, 2026

    @tartarughina
    Collaborator

    @sedax90 have you tried to use the whole initialization options I've suggested in #146 (comment)?

  18. sedax90 commented on Feb 27, 2026

    @sedax90
    Author

    @sedax90 have you tried to use the whole initialization options I've suggested in #146 (comment)?

    Yes I've reported it in #122 (comment)

  19. tartarughina commented on Mar 1, 2026

    @tartarughina
    Collaborator

    @sedax90 I've updated the initialization options in PR#205 and those should improve the behavior of JDTLS with Gradle and Maven projects. Let me know whether those are going to improve the situation for you

  20. sedax90 commented on Mar 6, 2026

    @sedax90
    Author

    @sedax90 I've updated the initialization options in PR#205 and those should improve the behavior of JDTLS with Gradle and Maven projects. Let me know whether those are going to improve the situation for you

    I can confirm who with settings and cleaning the cache is working fine!

  21. tartarughina commented on Mar 6, 2026

    @tartarughina
    Collaborator

    Awesome, glad to hear the new init options are doing their job

  22. matthieu-labas commented on May 28, 2026

    @matthieu-labas

    Is the .classpath file the same as the eclipse projects (XML file with <classpathentry> tags)? Or is there a documentation for the format somewhere (I haven't found it)?
    I'm trying to solve the same issue, opening a workspace directory containing multiple Eclipse projects built with Ant (I'm hoping to switch from Eclipse to Zed for Java development).

  23. tartarughina commented on May 28, 2026

    @tartarughina
    Collaborator

    Yes it is the same, we are using the same language server as Eclipse, JDTLS

  24. matthieu-labas commented on Jun 1, 2026

    @matthieu-labas

    Yes it is the same, we are using the same language server as Eclipse, JDTLS

    Would you happen to know whether the kind="var" entries can be handled? It seems only the kind="lib" entries are recognized by JDTLS:

    <classpathentry kind="lib" path="/path/to/libraries/commons-io-2.20.0.jar"/> <!-- Works -->
    <classpathentry kind="var" path="lib/commons-net-3.12.0.jar"/> <!-- Does not work -->

    The problem is that those variables are defined in the Eclipse Workspace, outside of the .classpath file.

    If you think it would be useful, I could open a new ticket.

  25. tartarughina commented on Jun 2, 2026

    @tartarughina
    Collaborator

    From a quick search I confirm what you said, kind=var expects to have some ENV vars available but those are created only within an Eclipse workspace.

    To confirm, would you convert the kind to lib and update the path to absolute?

  26. matthieu-labas commented on Jun 2, 2026

    @matthieu-labas

    I changed kind="var" to kind="lib" and updated to absolute path and it is indeed working.

    I'm not completely sure how the "var" kind it is handled inside the plugin/JDTLS but having a section somewhere in the plugin configuration where we could define such variables would be awesome. I tried exporting environment variables in the script that runs Zed and modifying the .classpath accordingly, to no avail:

    run-zed:

    export $LIBP=/path/to/libraries
    zed $@

    .classpath:

    <classpathentry kind="lib" path="$LIBP/commons-net-3.12.0.jar"/> <!-- Does not work -->
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

    language-serverRelated to the language server.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions