Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code can't find JDK8

I am currently trying to compile and run Java in VSC using redhat's extention and the code runner extension, though every time I try to "Run code," it tells me "Java runtime could not be located," and in the output: "'javac' is not recognized as an internal or external command, operable program or batch file." So I went into settings to tell VSC the path to my JDK. I went to "Java configuration" and inserted "java.home": C:\Program Files\Java\jre1.8.0_144 into the settings, though it gives me another error stating "Value Expected (2, 18)". This is where I'm stuck currently:

Where I'm Stuck Currently

I have also tried the directory to my JDK bin with the same results. What am I doing wrong?

like image 969
A. Duke Avatar asked Oct 15 '17 02:10

A. Duke


People also ask

Can we use Java 8 in VS Code?

You can still compile your projects with Java 8. JDK11 is only required to run vscode-java.

Where is JDK in VS Code?

Bring up the Command Palette (Ctrl+Shift+P) and then type java to search for this command. After selecting the command, you will be prompted for the location and name of the project. You can also choose your build tool from this command.

Why can't I run Java code in VS Code?

In order to run Java within Visual Studio Code, you need to install a JDK. The Extension Pack for Java supports Java version 1.5 or above. We recommend you to consider installing the JDK from one of these sources: Amazon Corretto.

Is JDK required for Visual Studio?

Android for Visual Studio requires Java Development Kit. Please install it or set Java Development Kit path on Tools->Options->Xamarin->Android Settings menu.


3 Answers

The format of syntax is wrong. Instead of writing -

    "java.home": C:\Program Files\Java\jre1.8.0_144

this should be written -

    "java.home": "C:/Program Files/Java/jdk1.8.0_144"

Use slash (/) instead of backslash () in file path and put quotes around it. Do recheck that jdk 8 or later is installed.

like image 107
abhay tripathi Avatar answered Oct 05 '22 05:10

abhay tripathi


I have faced the same problem if you are on Windows machine then open folder C:\Program Files\Java\ and look for the newest version of JDK in my case it's "jdk1.8.0_144" then enter on the right side following:

`{
     "java.home": "C:\\Program Files\\Java\\jdk1.8.0_144"
 }`

If you don't have at least 1.8 then install a new one! because VS code doesn't support older versions!

Your error says you need to put in double Slashes.

If you are on Linux then use normal slashes "/"

Don't forget to save and restart VS code afterward to apply changes! Have a nice day

like image 34
Neon Avatar answered Oct 05 '22 07:10

Neon


I fixed the issue by downloading OpenJDK from Red Hat openjdk and placing the extracted file in directory C:\ as in the image(I have renamed the file name from "java-1.8.0-openjdk-1.8.0.191-1.b12.redhat.windows.x86_64" to "java-1.8.0-openjdk-1.8.0.191" for simplicity) And change user settings in VS Code as USER SETTINGS and change workspace settings in VS Code as WORKSPACE SETTINGS

like image 29
MOHAMMAD WASEEM Avatar answered Oct 05 '22 05:10

MOHAMMAD WASEEM