skip to Main Content

I am Currently running VSCode 1.85.0 and it seems that no matter what I do, VSCode refuses to run any Java code. I successfully installed the VScode Java coding pack from

code.visualstudio.com/docs/languages/java

I also downloaded all of the Java extensions that were recommended. However, when I search Java: Create Java Project, nothing pops up. When I try to run

public class QuickStart{
public static void main(final String[] args) {
    System.out.println("Hello World!");
}

}

Nothing happens. When I run this same code from the command line directly, it runs without issue. When I type in Java –version in the command line I get

openjdk 17.0.9 2023-10-17
OpenJDK Runtime Environment Temurin-17.0.9+9 (build 17.0.9+9) OpenJDK
64-Bit Server VM Temurin-17.0.9+9 (build 17.0.9+9, mixed mode,
sharing)

So it appears Java has been installed correctly but VSCode is unaffected and does not recognize it. I’ve tried manually deleting all of the extensions and reinstalling them but that also did not work. I am at a total loss. It seems like installing the extensions effectively does nothing. Is there anything else I can try?

2

Answers


  1. (Solution 1/2). It is possible that you have not yet set the JAVA_Home environment variable yet.

    (Windows)

    1. In Search, search for and then select: System (Control Panel)
    2. Click the Advanced system settings link.
    3. Click Environment Variables. In the section System Variables find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
    4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
    5. Reopen Command prompt window, and run your java code.

    (Solution 2/2). configure your "java.home" path in your settings.json file

    Provide below is how to do so
    Changing the java.home path in VS code

    If neither of these solutions work, please reply.

    Login or Signup to reply.
  2. Set the JDK path below and use Java to extend the execution script.

    https://code.visualstudio.com/docs/java/java-project#_configure-runtime-for-projects

        "java.configuration.runtimes": [
            {
                "name": "JavaSE-1.8",
                "path": "E:\Program Files\Java\jdk1.8.0_341",
            },
            {
                "name": "JavaSE-17",
                "path": "E:\Program Files\Java\jdk-17.0.5",
                "default": true,
            }
        ],
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search