java JAVA_HOME 和 JAVA_PATH 的设置问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17596473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 02:25:40  来源:igfitidea点击:

setting issue of JAVA_HOME and JAVA_PATH

java

提问by user297850

I have been using Eclipse to develop java program on a windows 7 machine. It works. I also typed "java" from the command prompt, it also shows the help message. In other words, I think Java was correctly installed on this machine. However, when I open the "environmental variable" setting on this machine, I cannot find either "JAVA_HOME" setting and "JAVA PATH" setting. What is the problem of this?

我一直在使用 Eclipse 在 windows 7 机器上开发 java 程序。有用。我还在命令提示符下键入了“java”,它还显示了帮助消息。换句话说,我认为 Java 已正确安装在这台机器上。但是,当我在这台机器上打开“环境变量”设置时,我找不到“JAVA_HOME”设置和“JAVA PATH”设置。这是什么问题?

采纳答案by Bimalesh Jha

Some environment variables are defined at machine level and some are defined (and overwritten) at user account level. Just do following in windows cmd prompt:

有些环境变量是在机器级别定义的,有些是在用户帐户级别定义(并覆盖)的。只需在 Windows 中执行以下操作cmd prompt

c:\echo %PATH%or just type c:\path

c:\echo %PATH%或者只是输入 c:\path

and verify the output.

并验证输出。

You can also verify java home path by writing a simple Test class like following:

您还可以通过编写一个简单的 Test 类来验证 java 主路径,如下所示:

public class Test {
  public static void main(String[]s){
    System.out.println(System.getProperty("java.home"));
  }
}

回答by Nasir

Java also copies java.exe and javaw.exe under C:\Windows\System32, there's where your java is running from.

Java 还会将 java.exe 和 javaw.exe 复制到 C:\Windows\System32 下,您的 java 就在那里运行。

You can confirm that by using wherecommmand:

您可以使用命令来确认where

On my win7 machine:

在我的 win7 机器上:

>where java.exe
C:\Windows\System32\java.exe

回答by Russell Shingleton

There are multitudes of links to be fond on Google regarding how to solve this in Windows. These environment variables typically do not get setup by default when installing java.

关于如何在 Windows 中解决这个问题,Google 上有很多链接。默认情况下,安装 java 时通常不会设置这些环境变量。

Here are some 10 second finds with with answers:

以下是一些 10 秒的发现并附有答案:

How to set java_home on Windows 7?

如何在 Windows 7 上设置 java_home?

Setting the JAVA_HOME Variable in Windows

在 Windows 中设置 JAVA_HOME 变量

Installing Java on Windows 7 and setting-up the JAVA_HOME

在 Windows 7 上安装 Java 并设置 JAVA_HOME

回答by djangofan

With Java, Groovy, Git, Heroku, Maven, and many other projects, what I always do is this:

对于 Java、Groovy、Git、Heroku、Maven 和许多其他项目,我总是这样做:

1.  Unzip the software package into a directory, for example:
    C:\AeroFS\Java\jdk1.7.0_25
    C:\AeroFS\Groovy\groovy-2.0.5

2.  Create a HOME variable, such as JAVA_HOME or GROOVY_HOME that points to the
    above locations.

3.  Put these in your default system path by editing your PATH variable and 
    adding %JAVA_HOME%\bin  and %GROOVY_HOME%\bin to the end of your PATH.  In
    the case of JAVA_HOME only, you might want to put it at the beginning of 
    the PATH to override the java.exe that rests in the WINDOWS directory 
    location.

回答by zerocool

Check you PATH variable in Environment Variables. It must be set to jreInstallation/bin. Windows does not pick up java command from JAVA PATH, it picks java command from PATH variable.

检查环境变量中的 PATH 变量。它必须设置为 jreInstallation/bin。Windows 不会从 JAVA PATH 中选取 java 命令,而是从 PATH 变量中选取 java 命令。

Also note that once you install JDK, path is not set by installation to jdkInstallation/bin, you need to set it up explicitly.So unless you set the path to jdkInstallation/bin, javac wont be recognized.

还要注意的是,一旦安装了JDK,路径不是安装设置为jdkInstallation/bin,需要明确设置。所以除非你设置路径为jdkInstallation/bin,否则javac是不会被识别的。

回答by Ruchira Gayan Ranaweera

Check your path variable in windows environmental variables. At least Java path should be there .

在 Windows 环境变量中检查您的路径变量。至少应该有 Java 路径。

It may looks like this.

它可能看起来像这样。

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0\bin

回答by user2573056

You should set path and classpath variables. Here's the link you can follow for step by step instructions.

您应该设置路径和类路径变量。您可以按照以下链接获取分步说明。

[http://abodeqa.wordpress.com/2012/08/11/how-to-set-path/][1]

[http://abodeqa.wordpress.com/2012/08/11/how-to-set-path/][1]