8

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.

enter image description here

I've followed the instructions found in several places for setting JAVA_HOME in Windows 7.

enter image description here

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

enter image description here

Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
  • 2
    Did you restart your command console? environment variable changes don't take effect until the console has been closed and re-opened. Also you may need to add JAVA_HOME to your PATH environment variable. You can do this by editing the path and adding the entry `%JAVA_HOME%;` – Hunter McMillen Jun 22 '12 at 17:29

5 Answers5

12

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";
Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
8

Make sure that the jdk.xxxxx/jre/bin folder is in your PATH

Jeremy
  • 2,870
  • 3
  • 23
  • 31
  • Notice 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. – Philip Kirkbride Jun 22 '12 at 17:46
  • JAVA_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? – Jeremy Jun 22 '12 at 17:50
  • When I type Java in command prompt it seems to work, tells me the usage – Philip Kirkbride Jun 22 '12 at 17:56
  • 1
    Can you update your answer with the output from typing 'set' at the command prompt? – Jeremy Jun 22 '12 at 17:58
  • @Jeremy I ran 'set' and added to question. – Philip Kirkbride Jun 22 '12 at 18:10
  • Your screen shot does not show that you added the correct directory I suggested to your PATH. – Jeremy Jun 22 '12 at 18:15
  • @Jeremy I updated my files and ran set again and replaced the image in question. Is that right? – Philip Kirkbride Jun 22 '12 at 18:20
6
  1. 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

enter image description here

  1. Click the Environment Variables button.

  2. Under System Variables, click New.

  3. 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 .

enter image description here

  1. Open Command Prompt as Administrator.

  2. 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"

Taras Melnyk
  • 3,057
  • 3
  • 38
  • 34
5

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.

Community
  • 1
  • 1
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
1

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

user827992
  • 1,743
  • 13
  • 25