Skip to content
Happy Programming Guide
Start learning
Java

Java Not Working in VS Code

No IntelliSense, "cannot find symbol" on everything, or the run button does nothing? VS Code needs a JDK it can find and a project it can understand. The checks, in order.

A backlit keyboard in a dark room

Java in VS Code works well once three things line up: a JDK the editor can locate, the Extension Pack for Java, and a folder that is a recognisable project — Maven, Gradle, or a plain folder with a source root. When any one is off, symptoms range from no code completion to red underlines on every line to a run button that silently does nothing. The checks below go from the JDK outwards.

Step 1: the JDK#

Terminal
java -version
javac -version
echo $JAVA_HOME          # macOS/Linux
echo %JAVA_HOME%         # Windows cmd

Both commands must work and report the same version, and it must be a JDK, not a JRE — javac missing means JRE. The Java extension needs Java 17 or later to run itself, even when your project targets an older version. If java is not recognised at all, fix that first; the editor cannot find what the terminal cannot.

If the JDK is installed somewhere VS Code does not look, tell it explicitly in settings:

JSON
{
  "java.jdt.ls.java.home": "C:\\Program Files\\Eclipse Adoptium\\jdk-21.0.4.7-hotspot",
  "java.configuration.runtimes": [
    { "name": "JavaSE-21", "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-21.0.4.7-hotspot", "default": true }
  ]
}

The first setting is the JDK that runs the language server; the second is the list of JDKs available to your projects. Run Java: Configure Java Runtime from the command palette to see what the extension has detected.

Step 2: the extensions#

Install the Extension Pack for Java from Microsoft. It bundles the language server (Red Hat’s Language Support for Java), the debugger, the test runner, Maven and Gradle support, and a project manager. Installing only the language server, or only the debugger, produces a half-working setup.

After installing, open a .java file and watch the status bar. A small Java icon appears and shows the language server starting; hover over it for status. Then check the log: View, Output, and select Language Support for Java. Errors there name the actual problem.

Step 3: open the right folder#

This is the most common cause of “cannot find symbol” on every import. The language server needs a project to resolve classes against. It recognises:

  • A folder containing pom.xml (Maven).
  • A folder containing build.gradle or build.gradle.kts (Gradle).
  • A plain folder with a src directory, treated as an unmanaged project.

Open that folder with File, Open Folder. Opening a single .java file, or the parent folder of several projects, gives the server nothing to work with. The status bar shows the loaded project name when it has one.

Terminal
# A guaranteed-good test project
mkdir hello && cd hello && mkdir -p src
printf 'public class Hello { public static void main(String[] a) { System.out.println("hi"); } }' > src/Hello.java
code .

If completion works here and not in your project, the setup is fine and your project’s structure is what needs attention.

Errors that do not go away#

When the code compiles in the terminal but VS Code still shows red, the language server’s cached view of the project is stale:

  1. Run Java: Clean Java Language Server Workspace from the command palette and reload.
  2. If the project uses Maven, run Java: Reload Projects or click the refresh icon in the Java Projects view.
  3. For Lombok, the extension supports it automatically in current versions; if annotations are unresolved, update the extension pack.

Run and debug#

With the pack installed, a Run | Debug link appears above every main method, and F5 runs the current file. If nothing happens:

  • Check the Debug Console for an error — often a missing dependency or the wrong JDK for the project’s release setting.
  • Delete an old .vscode/launch.json that points at a class that no longer exists.
  • For a project that must be run through its build tool, use the terminal: mvn spring-boot:run, ./gradlew run.

Spring Boot#

Install the Spring Boot Extension Pack on top of the Java pack. It adds the Spring Boot Dashboard for starting and stopping applications, and understanding of Spring’s annotations and properties files. A Spring project that will not start from the dashboard but works with mvn spring-boot:run usually has a JDK mismatch: the project’s java.version in the pom against the JDK VS Code selected.

Slow or hanging#

The Java language server is a heavy process. First open of a large project can take a couple of minutes while it indexes; the status bar shows progress. If it hangs every time, give it more memory:

JSON
{ "java.jdt.ls.vmargs": "-Xmx2G -XX:+UseParallelGC" }

Questions people ask#

VS Code or IntelliJ for Java?

IntelliJ’s community edition is the stronger Java IDE, particularly for large projects and refactoring. VS Code is lighter and fine for learning, small projects and mixed-language work. Many people use both.

Which JDK should I install?

A current LTS: 21 or 25. Adoptium’s Temurin, Microsoft’s build and Oracle’s are all fine. The extension itself needs 17 or newer.

Can I use VS Code for a project targeting Java 8?

Yes. Install a 17+ JDK for the extension and a Java 8 JDK for the project, and list both in java.configuration.runtimes.

Why does the terminal use a different Java than the editor?

The terminal uses the PATH; the editor uses its settings. Make them agree by setting java.jdt.ls.java.home to the same JDK that which java reports.

Where to go next#

'cannot find symbol': the real compiler error, explainedRead next

Keep reading

Java

What’s New in Java 25 LTS

Java 25 is the current long-term release. Flexible constructors, compact source files, module imports and scoped values are final; here is what…

4 min read

Java

Java Input and Output (I/O)

Reading and writing files in Java: the modern Files and Path API, buffered streams for large files, reading keyboard input, and try-with-resources.

4 min read

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *