skip to Main Content

So, i am running a java project which have many library that are available in the current working directory but VS code seems to not recognize these library and giving out error "The import ###### cannot be resolved" ex: The import org.apache.pdfbox.pdmodel.PDDocument cannot be resolved"

here is the image that might help you to know more about it
This is the package that i am working on :
Here the org/apache is the library contain the class file that are need to be imported and FileArrangement.java is the file having the import statements

Error i have been receiving
this is what VS code is been showing

i really need your help because i really don’t have any idea how to correct this

I have checked other projects and they are also showing the same result although the import statements for java classes like . java.util.ArrayList doesn’t show any kind of error and i have tried to clean java in VS code it also didn’t work

i just need to correct this error of VS code to import the classes that i need
No error on java.util package

2

Answers


  1. Putting the libraries in your current working directory does not work for Java, you need to add them to the classpath.

    If you’re using maven, that manages the classpath for you.

    If not, you can manage it in VS Code by executing the Java: Configure Classpath command from the Command Palette (Ctrl+Shift+P).

    Login or Signup to reply.
  2. You can add dependencies via Referenced libraries under the JAVA PROJECTS panel.

    enter image description here

    Or use java.project.referencedLibraries setting in settings.json.

    For example:

    "java.project.referencedLibraries": [
        "library/**/*.jar",
        "/home/username/lib/foo.jar"
    ]
    

    Details can be found in configure-classpath and manage-dependencies.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search