Reputation: 22899
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
Upvotes: 26
Views: 302859
Reputation: 11650
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";
Upvotes: 30
Reputation: 3275
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"
Upvotes: 10
Reputation: 22899
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.
Upvotes: 11
Reputation: 1753
2 errors:
You are missing the bin
folder.
Usually the correct path is C:\Program Files\Java\jdk_version\bin
JAVA_HOME
is usually used by some script or program, if you are interested on running java tools from cmd
you have to add that directory to PATH
Upvotes: 2