Setting JAVA_HOME
Solution 1
As many have mentioned I had to add...
C:\Program Files\Java\jdk_version\bin
...to the path variable.
However what was not mentioned and was stopping this from working was that I had to make sure java\bin directory is in the path statement before the windows\system32 directory, otherwise this will not work.
I was able to find the information here.
Solution 2
Make sure that the jdk.xxxxx/jre/bin folder is in your PATH
Solution 3
-
Set the JAVA_HOME Variable
Windows 7 – Right click My Computer and select Properties > Advanced
Windows 8 – Go to Control Panel > System > Advanced System Settings
Windows 10 – Search for Environment Variables then select Edit the system environment variables
Click the Environment Variables button.
Under System Variables, click New.
-
In the Variable Name field, enter either:
JAVA_HOME if you installed the JDK (Java Development Kit)
or
JRE_HOME if you installed the JRE (Java Runtime Environment). In the Variable Value field, enter your JDK or JRE installation path .
Open Command Prompt as Administrator.
-
Set the value of the Environment variable to your JDK (or JRE) installation path as follows:
setx -m JAVA_HOME "C:\path_to_Java\jdk_version"
Solution 4
If you don't have admin rights, use the below command to set environment variables for java using the command prompt
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
Modify the environment variable.
setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx -m PATH "%PATH%;%JAVA_HOME%\bin";
Philip Kirkbride
Updated on August 18, 2021Comments
-
Philip Kirkbride over 2 years
I'm having a problem when running programs that use Java from the command line. I get back a message saying Java.exe could not be found.
I've followed the instructions found in several places for setting JAVA_HOME in Windows 7.
As can be seen in the image I'm pointing to the JDK folder as instructed, I've also tried several variations including linking to the bin folder(where java.exe is located).
What am I doing wrong, and how can I debug this.
EDIT:
Typing Set in Command Prompt outputs
-
Philip Kirkbride almost 12 yearsNotice the part of my question where I say " I've also tried several variations including linking to the bin folder(where java.exe is located)." Have tried it from the bin and I still get the same behavior. Restarted the command prompt but not the computer.
-
Jeremy almost 12 yearsJAVA_HOME and PATH are different, I didn't say point JAVA_HOME to the jre/bin directory. Try making sure that the PATH environment variable includes the jre/bin directory. For example, type java from the command prompt, does that work?
-
Philip Kirkbride almost 12 yearsWhen I type Java in command prompt it seems to work, tells me the usage
-
Jeremy almost 12 yearsCan you update your answer with the output from typing 'set' at the command prompt?
-
Philip Kirkbride almost 12 years@Jeremy I ran 'set' and added to question.
-
Jeremy almost 12 yearsYour screen shot does not show that you added the correct directory I suggested to your PATH.
-
Philip Kirkbride almost 12 years@Jeremy I updated my files and ran set again and replaced the image in question. Is that right?