-3

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?

5
  • Thanks for pointing that out, I will fix the link. I did download the VSCode from that site though Commented Dec 9, 2023 at 20:44
  • So, what extension did you install? What java jdk did you install? DId you first try the recommended method: code.visualstudio.com/docs/languages/… Commented Dec 9, 2023 at 20:46
  • The documentation mentions this important point: If you open a Java file in VS Code without opening its folder, the Java Language Server might not work properly. Commented Dec 9, 2023 at 20:48
  • 1
    I installed Amazon Corretto. I restarted my PC and it works now. Commented Dec 9, 2023 at 21:18
  • Introducing the Oracle Java Platform Extension for Visual Studio Code Commented Dec 9, 2023 at 23:23

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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,
        }
    ],

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.