Setting JAVA_HOME

2019-02-16 03:25发布

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

5条回答
虎瘦雄心在
2楼-- · 2019-02-16 03:46

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.

查看更多
再贱就再见
3楼-- · 2019-02-16 04:02

From the desktop, right click the Computer icon.

1. Choose Properties from the context menu.
2. Click the Advanced system settings link.
3. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

for more detail ..PATH and CLASSPATH

查看更多
太酷不给撩
4楼-- · 2019-02-16 04:04
  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"

查看更多
姐就是有狂的资本
5楼-- · 2019-02-16 04:05

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

查看更多
Lonely孤独者°
6楼-- · 2019-02-16 04:07

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

查看更多
登录 后发表回答