'How to set java classpath in Visual Studio Code (v 1.27.2)?

I am new to Visual Studio Code for Java development and I had a workspace open yesterday for testing. Now when restarting Visual Studio today, I get a "Classpath is incomplete" warning when I open any java file and I cannot get any tests to run. Looking at what must be the workspace file, it only contains the following. Is it missing something that sets the class path, or is there some other way to solve this problem?

{
    "folders": [
        {
            "path": "<path to project directory>"
        }
    ],
    "settings": {
        "java.configuration.updateBuildConfiguration": "automatic"
    }
}


Solution 1:[1]

I was able to solve this problem by using the File > Add Folder To Workspace option to create a new workspace that I can now run the debugger in.

Solution 2:[2]

Currently, using version 1.60.x, solved this with the following steps on MacOS

  • Cmd + Shift + P
  • Type: "Java: Configure Classpath", press enter
  • On the option screen that opens, scroll to the bottom, you'll see the "Referenced Libraries", click on "Add" and browse to the path of the Jars to reference, you can select multiple jars in a folder.
  • After doing this, you can run the "Java: Update Project" command or just try to run the Java code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S. Forman
Solution 2 tlogbon