JAVA_HOME Variable Issues
Asked Answered
E

9

11

I've seen the numerous other posts on here regarding JAVA_HOME variables and I have tried them all.

When I try and execute any gradle related tasks from the terminal I receive the following error:

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_191

Please set the JAVA_HOME variable in your environment to match the location of your Java Installation.

If I run WHERE java I get C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe and c:\jdk\bin\java.exe, which leads me to believe there's an issue somewhere with this.

I added C:\Program Files\Java\jdk1.8.0_191 to my path and added JAVA_HOME as a system variable pointing at C:\Program Files\Java\jdk1.8.0_191. What am I missing? I have been banging my head against this for a while now; any help would be greatly appreciated.

EDIT: I have confirmed that C:\Program Files\Java\jdk1.8.0_191 does in fact exist and the contents are

  • bin
  • include
  • jre
  • lib
  • man
  • COPYRIGHT
  • javafx-src.zip
  • LICENSE
  • README
  • release
  • src.zip
  • THIRDPARTYLICENSEREADME
  • THIRDPARTYLICENSEREADME-JAVAFX
Eldwon answered 4/2, 2020 at 20:58 Comment(23)
There is a quote in your path.Necessitous
What is producing the error message? ..check the contents of the (java) folders...Gatian
Set C:\jdk into JAVA_HOME variable.Disagreeable
@Necessitous It was a typo when I copy pasted. There is not actually a quote in my path variable. ApologiesEldwon
@Arvind That depends how Java is installed.Ceremonial
Also, if you're going to down vote a post; please give a reason why. I have provided all information, described attempts to fix, and have edited my typo.Eldwon
@Storms Do you need Java 8 still?? adoptopenjdk.net/installation.html#x64_win-jdkCeremonial
@cricket_007 Yes, the project i'm working with is Java 8. I'm using my company machine, which is why i'm dancing with config issues again.Eldwon
Are you using IntelliJ or Eclipse with your Gradle? Those have their own embedded Gradle configs and JREs. Do you need to use the terminal with Gradle?Ceremonial
Also, Java 11 can still compile Java 8 projects. I'm doing it right nowCeremonial
@cricket_007 I'm running Intellij and was directed to use 191 by the project manager.Eldwon
Can you upload a screenshot of this? jetbrains.com/help/idea/gradle.html#gradle_settings_accessCeremonial
Do you get same errors when doing this? jetbrains.com/help/idea/work-with-gradle-tasks.html#Ceremonial
Sidenote: This is really a case where having Vagrant or Docker build environments comes in handy.Ceremonial
Pardon me if this is a silly question, but I can't see anywhere in this entire post where it says that folder C:\Program Files\Java\jdk1.8.0_191 actually exists on your computer. So does it? And if it does, what files and folders does it contain?Voroshilovsk
@Voroshilovsk Edited question to reflect. Excellent pointEldwon
Open a command prompt window and type this command: javac -version.Voroshilovsk
@Voroshilovsk returns: javac 1.8.0_191Eldwon
Have you seen: Gradle finds wrong JAVA_HOME even though it's correctly set And what about: Windows 10 Gradle: JAVA_HOME is set to an invalid directory And then there is: JAVA_HOME is set to an invalid directory but it is set to the right directoryVoroshilovsk
You could always try using the short name, i.e. PROGRA~1 instead of Program Files. The command dir /X will display the short name.Voroshilovsk
have you managed to fix the issue?Resting
@LionelCichero No unfortunately notEldwon
have you tried https://mcmap.net/q/981609/-java_home-variable-issues? I remember once having almost the same issue and managed to fix it that way.Resting
S
9

Change your path variable to include %JAVA_HOME%\bin

Remove quote from your JAVA_HOME, it should just be C:\Program Files\Java\jdk1.8.0_191

Stockpile answered 4/2, 2020 at 20:59 Comment(4)
I made these change and am still receiving the same errors from the terminal.Eldwon
@Eldwon Did you restart the terminal after making the changes?Ceremonial
@cricket_007 Restarted the entire machine because overkill is underrated.Eldwon
It's working well for me.Altman
C
5

On linux you would do:

export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre"
not
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java"

Cowherd answered 5/2, 2021 at 21:56 Comment(0)
R
3

If you check your PATH variable you will probably find that this directory "C:\Program Files (x86)\Common Files\Oracle\Java\javapath" appears before your JAVA_HOME directory.

Try changing the order, for example:

Instead of:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;%JAVA_HOME%\bin

Make it like this:

%JAVA_HOME%\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath
Resting answered 4/2, 2020 at 21:24 Comment(1)
i needed to edit the system variable path to make it work.Baucom
A
1

set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_101" (note that: you should set it to your own path)

set Path="%JAVA_HOME%\bin"

(very important)

finish.

Agonized answered 18/7, 2022 at 3:38 Comment(0)
P
1

For me the issue was with the way openjdk sets JAVA_HOME variable.

  1. Make sure your JAVA_HOME variable is set like this

    export JAVA_HOME="/usr/local/opt/openjdk@17"

// NOTICE THERE IS NO /bin appended

  1. Then for the PATH variable you can append the "/bin"

    export PATH="$PATH:$JAVA_HOME/bin"

Polarization answered 7/7, 2023 at 13:35 Comment(0)
J
0

Well, you will define JAVA_HOME, if your installation was default probably the path is "C:\Program Files (x86)\Java\jdk1.8.0_60" and then you will define Path variable with %JAVA_HOME%\bin;

Some tutorials tell you to config the Classpath as well, but this is not necessary.

Jilt answered 4/2, 2020 at 21:19 Comment(0)
P
0

I was creating a maven project and while creating the project I was getting the same error. I have installed Java in H drive. the installed files are in H:\Java. In environment variable I did two things. first I created a local variable Variable name = JAVA_HOME. Variable value = H:\Java

Second in path variable I added one more path. %JAVA_HOME%; H:\JAVA; and restarted the IDE again and it worked

Parton answered 15/6, 2021 at 7:57 Comment(0)
L
0

I fixed it by removing "\bin" from the path and saved it in a path that does NOT contain spaces. Example: Program Files\xx\xx is wrong Java/download/xx is right

Lincoln answered 1/1 at 13:50 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Biostatics
S
-1

you can go on environment variables and browse the path of the java jdk you want to use. the higher jdk does not seem to work properly with java environments.

here, you are using jdk 11 instead of that you can use lower version jdk like: jdk 1.8_0_201.

Stoneman answered 27/6, 2021 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.