Vscode-java: Cannot find JDK

Created on 13 Oct 2016  路  20Comments  路  Source: redhat-developer/vscode-java

ok so I have my JAVA_HOME set to the home path for the redhat jdk-8 but still get the error that its not installed and cannot be started.

what else do I have to do to get this to work?
I have looked through the other posts but have yet to find a solution.
this is on windows 10 btw.

bug need info

Most helpful comment

It was happening the same to me in Ubuntu 18.04, where the $JAVA_HOME variable was pointing to:
"/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
So I just changed the User Settings to the following value and it worked (removed the /bin/java):
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"

Doesn't work for Kali Linux v2019.4
Any Suggestions?

{
    "workbench.editor.enablePreview": false,
    "workbench.editor.enablePreviewFromQuickOpen": false,
    "java.home": "/usr/lib/jvm/java-11-openjdk-amd64",
    "editor.suggestSelection": "first",
}

image

@miteshgoplani See if you installed both jdk and jre I had the same problem I only installed jre. After installing jdk add this to settings.json

"java.home": "/usr/lib/jvm/java-11-openjdk-amd64",

All 20 comments

Can you paste the path you used here?
Also can you check if you still have the issue with the new release (0.0.5)?
BTW, you can now set up the java.home variable in VS Code preferences, starting in 0.0.5.

Can you add support for variable JDK_HOME and JAVA_HOME instead of having to compulsorily use java.home ?

In the 20 years I have been programming with Java, my understanding is that the way the environment variables being used is to have the JRE be pointed by the JAVA_HOME and the JDK be pointed by JDK_HOME. In case developers want, they can point both to the JDK.

Look at documentation here for some reference:
https://docs.oracle.com/cd/E35865_01/doc.1120/e29687/preinstall.htm#CIHCIHDE
https://docs.oracle.com/cd/E13222_01/wls/docs/techstart/environment.html

@navneetkarnani _java.home_ configuration is NOT mandatory. We have added it as a way to override the _JAVA_HOME_ for situations such as developer needs JAVA_HOME to point to JDK which is not sufficient for running our tools. See #28 for full discussion.

In @TTanner21's case we are still trying to determine why _JAVA_HOME_ is not automatically discovered, using _java.home_ with the same value as _JAVA_HOME_ would hint us that the path is actually good.

Can you paste the path you used here?
Also can you check if you still have the issue with the new release (0.0.5)?
BTW, you can now set up the java.home variable in VS Code preferences, starting in 0.0.5.

the path is C:\java-1.8.0-openjdk-1.8.0.102-1
I don't know why its not working, but using the java.home variable does work with the same path.

@TTanner21 You need to escape the backslashes in the configuration.

From my user settings:
"java.home": "D:\\Dev\\jdk\\jdk1.8.0_25_x86"

I have this same issue and had to paste my JDK_Home environment variable value into the VSC java.home setting, escaping the backslashes. Is it possible that you guys need to escape the backslashes when using JDK_Home for some reason?

@carlin-q-scott What is your OS?

@gorkem Windows 10 Home.

I also seem to be having issues with this. I have correctly set my java.home workspace setting to:

"java.home": "C:\\Program Files\\Java\\jdk1.8.0_162"

When running a maven build task I get the error in console:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.068 s
[INFO] Finished at: 2018-02-08T22:18:53-05:00
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project HelpMeAdvanced-Sponge: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

EDIT: The only way I've been able to successfully run commands is if I set JAVA_HOME system environment variable. So for some reason it seems to be ignoring all other settings even though the check order that is documented lists java.home workspace setting first.

@kmccmk9 Running the Java editor is one thing, running Maven from CLI is another. Those are 2 pieces of software each requiring their settings.
The java.home preference is only used by vscode-java (actually the underlying jdt.ls backend). Maven is not aware of vscode preferences.
If you set JAVA_HOME globally on your system, then vscode-java should be able to pick it up, Maven too.

It was happening the same to me in Ubuntu 18.04, where the $JAVA_HOME variable was pointing to:
"/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
So I just changed the User Settings to the following value and it worked (removed the /bin/java):
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"

It was happening the same to me in Ubuntu 18.04, where the $JAVA_HOME variable was pointing to:
"/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
So I just changed the User Settings to the following value and it worked (removed the /bin/java):
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"

Fixed it for me.

I am on fedora, and I have it set to
"java.home": "/usr/lib/jvm/java-11-openjdk-11.0.5.10-0.fc30.x86_64" and it doesnt want to work for me. Any thoughts?

@PhazonicRidley you can try the following:

sudo dnf install java-11-openjdk java-11-openjdk-devel
code ...

It was happening the same to me in Ubuntu 18.04, where the $JAVA_HOME variable was pointing to:
"/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
So I just changed the User Settings to the following value and it worked (removed the /bin/java):
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"

This is not working for me... What can I do..
aaaaa

@meSajied if the path is correct. I think what you need to do is adding , after the } at line 15

It was happening the same to me in Ubuntu 18.04, where the $JAVA_HOME variable was pointing to:
"/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
So I just changed the User Settings to the following value and it worked (removed the /bin/java):
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"

Doesn't work for Kali Linux v2019.4
Any Suggestions?

{
    "workbench.editor.enablePreview": false,
    "workbench.editor.enablePreviewFromQuickOpen": false,
    "java.home": "/usr/lib/jvm/java-11-openjdk-amd64",
    "editor.suggestSelection": "first",
}

image

It was happening the same to me in Ubuntu 18.04, where the $JAVA_HOME variable was pointing to:
"/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
So I just changed the User Settings to the following value and it worked (removed the /bin/java):
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"

Doesn't work for Kali Linux v2019.4
Any Suggestions?

{
    "workbench.editor.enablePreview": false,
    "workbench.editor.enablePreviewFromQuickOpen": false,
    "java.home": "/usr/lib/jvm/java-11-openjdk-amd64",
    "editor.suggestSelection": "first",
}

image

@miteshgoplani See if you installed both jdk and jre I had the same problem I only installed jre. After installing jdk add this to settings.json

"java.home": "/usr/lib/jvm/java-11-openjdk-amd64",

Yes make sure you use a JDK, not a JRE, and don't set the path to bin/ or bin/java.

Was this page helpful?
0 / 5 - 0 ratings