Setting JAVA_HOME

77,157

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

  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"

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";
Share:
77,157
Philip Kirkbride
Author by

Philip Kirkbride

Updated on August 18, 2021

Comments

  • Philip Kirkbride
    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.

    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

  • Philip Kirkbride
    Philip Kirkbride almost 12 years
    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.
  • Jeremy
    Jeremy almost 12 years
    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?
  • Philip Kirkbride
    Philip Kirkbride almost 12 years
    When I type Java in command prompt it seems to work, tells me the usage
  • Jeremy
    Jeremy almost 12 years
    Can you update your answer with the output from typing 'set' at the command prompt?
  • Philip Kirkbride
    Philip Kirkbride almost 12 years
    @Jeremy I ran 'set' and added to question.
  • Jeremy
    Jeremy almost 12 years
    Your screen shot does not show that you added the correct directory I suggested to your PATH.
  • Philip Kirkbride
    Philip Kirkbride almost 12 years
    @Jeremy I updated my files and ran set again and replaced the image in question. Is that right?