StormsEdge
StormsEdge

Reputation: 885

JAVA_HOME Variable Issues

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

Upvotes: 11

Views: 96590

Answers (9)

Maxim M
Maxim M

Reputation: 336

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

  2. Then for the PATH variable in your config you can append the "/bin"

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

Upvotes: 1

luckyStacker
luckyStacker

Reputation: 11

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

Upvotes: 0

wang lulu
wang lulu

Reputation: 11

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.

Upvotes: 1

Deepshika Ghale
Deepshika Ghale

Reputation: 11

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.

Upvotes: -1

Shivam Jaiswal
Shivam Jaiswal

Reputation: 11

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

Upvotes: 0

Elmasry
Elmasry

Reputation: 132

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"

Upvotes: 5

Lionel Cichero
Lionel Cichero

Reputation: 563

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

Upvotes: 3

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.

Upvotes: 0

rhowell
rhowell

Reputation: 1187

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

Upvotes: 10

Related Questions