28

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

1
  • 5
    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%; Commented Jun 22, 2012 at 17:29

6 Answers 6

37

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";
Sign up to request clarification or add additional context in comments.

Comments

13

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.

Comments

12
  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"

Comments

8

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

7 Comments

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.
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?
When I type Java in command prompt it seems to work, tells me the usage
Can you update your answer with the output from typing 'set' at the command prompt?
@Jeremy I ran 'set' and added to question.
|
2

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

Comments

0

I am running Linux. I had JAVA_HOME working well over a year ago, but during the last few months, the published formulas have all resulted in tracebacks. This is a sign of an unstable, unusable OS.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.