如何在Windows 7上设置java_home ?

时间:2021-06-21 23:02:19

I went to the Environment Variables in 'System' in the control panel and made two new variables, one for user variables and one for system variables. Both were named JAVA_HOME and both pointing to

我在控制面板的“System”中访问了环境变量,并创建了两个新变量,一个用于用户变量,一个用于系统变量。两者都被命名为JAVA_HOME并且都指向

C:\Sun\SDK\jdk\bin

C:\ Sun jdk \ SDK \ \ bin

But for some reason, I still get the below error when running a Java command...

但是由于某些原因,我在运行Java命令时仍然会得到以下错误……

BUILD FAILED
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:161: The following error  occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:141: The following error occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:137: Please set java.home to a JDK installation

Total time: 1 second
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish>lib\ant\bin\ant -f setup.xml
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: setup.xml

How can I fix this problem?

我如何解决这个问题?

17 个解决方案

#1


620  

Find JDK Installation Directory

找到JDK安装目录

First you need to know the installation path for the Java Development Kit.

首先,您需要知道Java开发工具包的安装路径。

Open the default installation path for the JDK:

打开JDK的默认安装路径:

C:\Program Files\Java

There should be a subdirectory like:

应该有如下子目录:

C:\Program Files\Java\jdk1.6.0_10

Note: one has only to put the path to the jdk without /bin in the end (as suggested on a lot of places). e.g. C:\Java\jdk1.6.0_31 and NOT C:\Java\jdk1.6.0_31\bin !

注意:您只需将路径放置到jdk而最终没有/bin(正如在许多地方建议的那样)。\Java\jdk1.6.0_31\而不是C:\Java\jdk1.6.0_31\bin !


Set the JAVA_HOME Variable

设置JAVA_HOME变量

Once you have the JDK installation path:

一旦您有了JDK安装路径:

  1. Right-click the My Computer icon on your desktop and select Properties.
  2. 右键单击桌面的My Computer图标并选择Properties。
  3. Click the Advanced tab, then click the Environment Variables button.
  4. 单击Advanced选项卡,然后单击Environment Variables按钮。
  5. Under System Variables, click New.
  6. 在系统变量下,单击New。
  7. Enter the variable name as JAVA_HOME.
  8. 输入变量名JAVA_HOME。
  9. Enter the variable value as the installation path for the Java Development Kit.
  10. 输入变量值作为Java开发工具包的安装路径。
  11. Click OK.
  12. 单击OK。
  13. Click Apply Changes.
  14. 单击Apply变化。

Note: You might need to restart Windows

注意:您可能需要重新启动Windows

The complete article is here, on my blog: Setting JAVA_HOME Variable in Windows.

完整的文章在这里,在我的博客上:在Windows中设置JAVA_HOME变量。

Get Video Solution.

得到视频解决方案。

#2


142  

What worked for me was adding the %JAVA_HOME%\bin to the Path environment variable with the JAVA_HOME environment variable pointing to the jdk folder.

对我有用的是将%JAVA_HOME%\bin添加到Path环境变量中,JAVA_HOME环境变量指向jdk文件夹。

#3


113  

You have to first Install JDK in your system.

您必须首先在系统中安装JDK。

Set Java Home

设置Java回家

JAVA_HOME = C:\Program Files\Java\jdk1.7.0 [Location of your JDK Installation Directory]

JAVA_HOME = C:\Program Files\Java\jdk1.7.0(JDK安装目录的位置)

Once you have the JDK installation path:

一旦您有了JDK安装路径:

  • Right-click the My Computer icon on
  • 右键单击My Computer图标
  • Select Properties.
  • 选择Properties。
  • Click the Advanced system setting tab on left side of your screen
  • 单击屏幕左侧的高级系统设置选项卡
  • Aadvance Popup is open.
  • Aadvance弹出开放。
  • Click on Environment Variables button.
  • 单击“环境变量”按钮。

如何在Windows 7上设置java_home ?

  • Under System Variables, click New.
  • 在系统变量下,单击New。
  • Enter the variable name as JAVA_HOME.
  • 输入变量名JAVA_HOME。
  • Enter the variable value as the installation path for the Java Development Kit.
  • 输入变量值作为Java开发工具包的安装路径。
  • Click OK.
  • 单击OK。
  • Click Apply Changes.
  • 单击Apply变化。

Set JAVA Path under system variable

在系统变量下设置JAVA路径。

PATH= C:\Program Files\Java\jdk1.7.0; [Append Value with semi-colon]

路径= C:\Program Files\Java\ jdk1.7.0;(附加价值与分号)

如何在Windows 7上设置java_home ?

#4


22  

In cmd (temporarily for that cmd window):

在cmd中(临时用于cmd窗口):

set JAVA_HOME="C:\\....\java\jdk1.x.y_zz"

echo %JAVA_HOME%

set PATH=%PATH%;%JAVA_HOME%\bin

echo %PATH%

#5


16  

http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html

http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html

Control Panel > Java, Java tab, click the View button. In Runtime Parameters, put:

控制面板> Java, Java选项卡,点击查看按钮。在运行时参数,将:

-Djava.home=YOUR_PATH_HERE

Or when you execute Java you can add that command line switch to the command:

或者当您执行Java时,您可以将命令行切换添加到命令:

java -Djava.home=PATH SomeJavaApp

#6


14  

You need to set it to C:\Sun\SDK\jdk (Assuming that is where the JDK is installed - It is not the default) - Do not put the \bin in C:\Sun\SDK\jdk\bin.

您需要将它设置为C:\Sun\SDK\jdk(假设jdk就安装在那里——它不是默认设置)—不要将\bin放在C:\Sun\SDK\jdk\bin中。

If your app only runs when you are logged in as the current user then put it in the user variables - If it needs to run for all users on your system then put it in System variables.

如果你的应用程序只在你作为当前用户登录时才运行,那么就把它放在用户变量中——如果它需要为系统上的所有用户运行,那么就把它放在系统变量中。

You might also need to add %JAVA_HOME%\bin to the path also (Also it depends on whether you run it from just the user or from all users, including System)

您可能还需要将%JAVA_HOME%\bin添加到路径中(也取决于您是从用户还是从所有用户,包括系统中运行它)

#7


7  

This is the official solution for setting the Java environment from www.java.com - here.

这是在www.java.com -这里设置Java环境的官方解决方案。

There are solutions for Windows 7, Windows Vista, Windows XP, Linux/Solaris and other shells.

有针对Windows 7、Windows Vista、Windows XP、Linux/Solaris和其他shell的解决方案。


Example

Windows 7

  1. Select Computer from the Start menu
  2. 从“开始”菜单中选择“计算机”
  3. Choose System Properties from the context menu
  4. 从上下文菜单中选择系统属性
  5. Click Advanced system settings -> Advanced tab
  6. 点击高级系统设置->高级标签
  7. Click on Environment Variables, under System Variables, find PATH, and click on it.
  8. 单击系统变量下的环境变量,找到路径,并单击它。
  9. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
  10. 在“编辑”窗口中,通过将类的位置添加到“路径”的值来修改路径。如果没有项路径,可以选择添加一个新变量,并添加路径作为名称,添加类的位置作为值。
  11. Reopen Command prompt window, and run your Java code.
  12. 重新打开命令提示窗口,运行Java代码。

#8


6  

For those who are still stumped with this problem (I tried all the above suggestions) --

对于那些仍然被这个问题难住的人(我尝试了以上所有的建议)—

If you're on a 64-bit version of Windows and you've installed the 32-bit JDK, besides adjusting PATH variables, you may need to adjust registry variables, too.

如果您使用的是64位版本的Windows,并且安装了32位JDK,那么除了调整路径变量之外,您可能还需要调整注册表变量。

I was pulling my hair out, having correctly set my PATH variables -- still to no avail -- and then only finding "vacated" Java entries in my registry, seemingly a deadend of fixing the "misfiring" Java Runtime Environment.

我绞尽脑汁,正确地设置了路径变量(仍然没用),然后在我的注册表中只找到“空出”的Java条目,这似乎是修复“故障”Java运行时环境的一个死胡同。

By using Process Monitor to watch the program I was trying to get started, in order to sniff out where it was looking in the registry for Java (Runtime Environment), I triumphantly discovered that it's looking in the 32-bit version of registry entries, found in HKEY_LOCAL_MACHINE\SOFTWARE\**Wow6432Node**\JavaSoft\Java Runtime Environment.

通过使用Process Monitor监视我正在尝试启动的程序,为了找出它在注册表中查找Java(运行时环境)的位置,我成功地发现它正在查找注册表项的32位版本,在HKEY_LOCAL_MACHINE\SOFTWARE\* Wow6432Node* \* javask\ 32 node *\Java运行时环境中找到。

Within that key, you should find subkeys of different Java versions installed (past and/or present). Click on the subkey of the latest version (my subkey is currently 1.7.0_25, for example). After clicking on that subkey, you'll see registry string values listed on the right, and particularly, JavaHome and RuntimeLib. You need to modify the values of those two values to reflect the both the current folder and jvm.dll file, respectively.

在该键中,您应该找到安装了不同Java版本的子键(过去和/或现在)。单击最新版本的子键(例如,我的子键当前为1.7.0_25)。单击该子键之后,您将看到在右侧列出的注册表字符串值,尤其是JavaHome和RuntimeLib。您需要修改这两个值的值,以反映当前文件夹和jvm。分别dll文件。

For example, in my case, the values were (previously) respectively set at C:\Program Files (x86)\Java\jre7 and C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll which are nonexistent on my machine. I had to update these to the current folder and file of C:\Program Files (x86)\Java\jdk1.7.0_25\jre and C:\Program Files (x86)\Java\jdk1.7.0_25\jre\bin\client\jvm.dll.

例如,在我的例子中,价值观(以前)分别设置在C:\Program Files (x86)\Java\jre7 C:\Program Files (x86)\Java\jre7\bin\client\jvm.在我的机器上不存在的dll。我不得不更新这些当前的文件夹和文件C:\Program Files (x86)\Java\ jdk1.7.0_25 \ jre和C:\Program Files (x86)\Java\ jdk1.7.0_25 \ jre \ bin \ client \ jvm.dll。

Again, this will depend entirely on both what version of Java (JDK and/or JRE) you have installed -- 32 or 64-bit -- and what type of operating system you're on -- 32 or 64-bit. Just know that they're reflected in different locations within the registry (like the Wow6432Node for 32 bit applications, in my case with the 32-bit JDK installed on a 64-bit machine).

同样,这完全取决于您安装的Java版本(JDK和/或JRE)(32位或64位)以及您使用的操作系统类型(32位或64位)。只需知道它们反映在注册表中的不同位置(比如32位应用程序的Wow6432Node,在我的例子中是安装在64位机器上的32位JDK)。

Now that I've updated those two registry values, my program runs flawlessly, with no more hiccups or complaints about a missing Java Runtime Environment (stemming from the registry).

现在我已经更新了这两个注册表值,我的程序运行得非常完美,不再出现任何问题,也不再抱怨缺少Java运行时环境(来自注册表)。

#9


6  

One Image can fix this issue. 如何在Windows 7上设置java_home ?

一个图像可以解决这个问题。

For More

更多的

#10


5  

Windows 7

  1. Go to Control Panel\All Control Panel Items\User Accounts using Explorer (not Internet Explorer!)

    转到控制面板\所有控制面板项目\用户帐户使用资源管理器(不是Internet Explorer!)

    or

    • click on the Start button

      单击“开始”按钮

      如何在Windows 7上设置java_home ?

    • click on your picture

      点击你的照片

      如何在Windows 7上设置java_home ?

  2. Change my environment variables

    改变我的环境变量

    如何在Windows 7上设置java_home ?

  3. New...

    新…

    如何在Windows 7上设置java_home ?

    (if you don't have enough permissions to add it in the System variables section, add it to the User variables section)

    (如果您没有足够的权限将其添加到系统变量部分中,请将其添加到用户变量部分)

  4. Add JAVA_HOME as Variable name and the JDK location as Variable value > OK

    添加JAVA_HOME作为变量名,JDK位置作为变量值>

    如何在Windows 7上设置java_home ?

Test:

测试:

  • open a new console (cmd)
  • 打开一个新的控制台(cmd)
  • type set JAVA_HOME
    • expected output: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
    • 预期的输出:JAVA_HOME = C:\ Program Files \ Java \ jdk1.8.0_60
  • 类型设置JAVA_HOME期望输出:JAVA_HOME=C:\程序文件\Java\jdk1.8.0_60。

#11


4  

In Eclipse: Window->Preferences->Java->Installed JREs

在Eclipse中:窗口- >首选项- > Java - >安装jre

Use the search feature to make sure your latest Java installation is listed; then make sure it is the one that is checked. This should be a JDK not a JRE.

使用搜索功能确保列出了最新的Java安装;然后确保它是被检查的那个。这应该是一个JDK而不是JRE。

#12


4  

While adding your Java directory to your PATH variable, you might want to put it right at the beginning of it. I've had the problem, that putting the Java directory at the end of the PATH would not work. After checking, I've found java.exe in my Windows\System32 directory and it looks like the first one wins, when there are several files with the same name in your PATH...

在将Java目录添加到PATH变量时,您可能希望将它放在它的开头。我遇到了一个问题,将Java目录放在路径的末尾将不起作用。检查后,我找到了java。在我的Windows\System32目录下的exe,当您的路径中有几个文件名相同的文件时,它看起来是第一个。

#13


4  

We need to make a distinction between the two environment variables that are discussed here interchangeably. One is the JAVA_HOME variable. The other is the Path variable. Any process that references the JAVA_HOME variable is looking for the search path to the JDK, not the JRE. The use of JAVA_HOME variable is not meant for the Java compiler itself. The compiler is aware of its own location. The variable is meant for other software to more easily locate the compiler. This variable is typically used by IDE software in order to compile and build applications from Java source code. By contrast, the Windows CMD interpreter, and many other first and third party software references the Path variable, not the JAVA_HOME variable.

我们需要区分这里讨论的两个环境变量。一个是JAVA_HOME变量。另一个是路径变量。任何引用JAVA_HOME变量的进程都在寻找到JDK的搜索路径,而不是JRE。使用JAVA_HOME变量并不适合Java编译器本身。编译器知道自己的位置。该变量用于其他软件更容易地定位编译器。IDE软件通常使用这个变量,以便从Java源代码编译和构建应用程序。相比之下,Windows CMD解释器和其他许多第一和第三方软件引用的是Path变量,而不是JAVA_HOME变量。

Use case 1: Compiling from CMD

用例1:从CMD编译

So for instance, if you are not using any IDE software, and you just want to be able to compile from the CMD, independent of your current working directory, then what you want is to set the Path variable correctly. In your case, you don't even need the JAVA_HOME variable. Because CMD is using Path, not JAVA_HOME to locate the Java compiler.

例如,如果您不使用任何IDE软件,并且您只是希望能够从CMD编译,独立于当前工作目录,那么您需要的是正确地设置路径变量。在您的示例中,甚至不需要JAVA_HOME变量。因为CMD使用的是Path,而不是JAVA_HOME来定位Java编译器。

Use case 2: Compiling from IDE

用例2:从IDE编译

However, if you are using some IDE software, then you have to look at the documentation first of all. It may require JAVA_HOME to be set, but it may also use another variable name for the same purpose. The de-facto standard over the years has been JAVA_HOME, but this may not always be the case.

但是,如果您正在使用一些IDE软件,那么您必须首先查看文档。它可能需要设置JAVA_HOME,但它也可能出于相同的目的使用另一个变量名。多年来事实上的标准一直是JAVA_HOME,但情况可能并不总是如此。

Use case 3: Compiling from IDE and CMD

用例3:从IDE和CMD编译。

If in addition to the IDE software you also want to be able to compile from the CMD, independent of your current working directory, then in addition to the JAVA_HOME variable you may also need to append the JDK search path to the Path variable.

如果除了IDE软件之外,您还希望能够从CMD编译,独立于当前工作目录,那么除了JAVA_HOME变量之外,您可能还需要将JDK搜索路径附加到path变量。

JAVA_HOME vs. Path

JAVA_HOME与路径

If your problem relates to compiling Java, then you want to check the JAVA_HOME variable, and Path (where applicable). If your problem relates to running Java applications, then you want to check your Path variable.

如果您的问题与编译Java有关,那么您需要检查JAVA_HOME变量和路径(如适用)。如果您的问题与运行Java应用程序有关,那么您需要检查路径变量。

Path variable is used universally across all operating systems. Because it is defined by the system, and because it's the default variable that's used for locating the JRE, there is almost never any problem running Java applications. Especially not on Windows where the software installers usually set everything up for you. But if you are installing manually, the safest thing to do is perhaps to skip the JAVA_HOME variable altogether and just use the Path variable for everything, for both JDK and the JRE. Any recent version of an IDE software should be able to pick that up and use it.

路径变量在所有操作系统中通用。因为它是由系统定义的,而且由于它是用于定位JRE的默认变量,所以运行Java应用程序几乎没有任何问题。尤其是在Windows系统上,安装软件的人通常会为你设置好一切。但是,如果您手动安装,最安全的做法可能是完全跳过JAVA_HOME变量,并仅为JDK和JRE使用路径变量。任何一个IDE软件的最新版本都应该能够选择并使用它。

Symlinks

符号链接

Symbolic links may provide yet another way to reference the JDK search path by piggybacking one of the existing environment variables.

符号链接可能提供了另一种方法来引用JDK搜索路径,它支持现有的环境变量之一。

I am not sure about previous versions of Oracle/Sun JDK/JRE releases, but at least the installer for jdk1.8.0_74 appends the search path C:\ProgramData\Oracle\Java\javapath to the Path variable, and it puts it at the beginning of the string value. This directory contains symbolic links to the java.exe, javaw.exe and javaws.exe in the JRE directory.

我不确定Oracle/Sun JDK/JRE的以前版本,但是至少jdk1.8.0_74的安装程序将搜索路径C:\ProgramData\Oracle\Java\javapath附加到path变量中,并将其放在字符串值的开头。这个目录包含了java的符号链接。exe,javaw。exe和javaw。JRE目录中的exe。

So at least with the Java 8 JDK, and presumably the Java 8 JRE standalone, no environment variable configuration needs to be done for the JRE. As long as you use the installer package to set it up. There may be differences on your Windows installation however. Note that the Oracle JRE comes bundled with the JDK.

因此,至少对于Java 8 JDK,以及独立的Java 8 JRE,不需要为JRE做环境变量配置。只要您使用安装程序包来设置它。但是,您的Windows安装可能存在差异。注意,Oracle JRE附带了JDK。

If you ever find that your Java JDK configuration is using the wrong version of the compiler, or it appears to be working by magic, without being explicitly defined so (without casting the spell), then you may have a symlink somewhere in your environment variables. So you may want to check for symlink.

如果您发现您的Java JDK配置使用了错误的编译器版本,或者它似乎是通过魔法工作的,而没有显式地定义它(不使用拼写),那么您的环境变量中可能有一个符号链接。你可能想要检查symlink。

#14


3  

Run Eclipse as Administrator.

以管理员身份运行Eclipse。

That solved my problem. I'm still digging for the logic behind it.

这解决了我的问题。我还在寻找它背后的逻辑。

#15


2  

if you have not restarted your computer after installing jdk just restart your computer.

如果您在安装jdk后没有重启计算机,请重新启动计算机。

if you want to make a portable java and set path before using java, just make a batch file i explained below.

如果您想在使用java之前创建一个可移植的java并设置路径,只需创建一个我在下面解释过的批处理文件。

if you want to run this batch file when your computer start just put your batch file shortcut in startup folder. In windows 7 startup folder is "C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"

如果您想在计算机启动时运行此批处理文件,请将批处理文件快捷方式放在startup文件夹中。在windows 7启动文件夹是“C:\用户\应用程序\漫游微软\ windows \ windows \启动菜单\程序\启动”

make a batch file like this:

制作一个这样的批处理文件:

set Java_Home=C:\Program Files\Java\jdk1.8.0_11
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_11\bin

note: java_home and path are variables. you can make any variable as you wish. for example set amir=good_boy and you can see amir by %amir% or you can see java_home by %java_home%

注意:java_home和path是变量。你可以随心所欲地设置任何变量。例如,set amir=good_boy,你可以看到amir% amir%或者java_home% java_home%

#16


2  

goto Mycomputer(This PC) -> rightclick ->select properties -> Advanced system settings -> environment variables-> in system variables click "New" button and write JAVA_HOME in variable name and path C:\Program Files\Java\jdk1.8.0_131 were jdk is present in variable value-> click ok.

goto Mycomputer(PC)- > rightclick - >选择属性- >高级- >环境变量- >系统设置在系统变量单击“新”按钮,写JAVA_HOME变量名和路径C:\Program Files\Java\ jdk1.8.0_131是jdk中变量值- >单击ok。

close and reopen the command prompt after setting JAVA_HOME. Sometimes changes does not reflect in the cmd opened before setting the JAVA_HOME.

在设置JAVA_HOME之后关闭并重新打开命令提示符。有时更改不会反映在设置JAVA_HOME之前打开的cmd中。

you can also set JAVA_HOME through terminal itself: SET JAVA_HOME="C:\Program Files (x86)\Java\jdk1.8.0_131"

您还可以通过终端本身设置JAVA_HOME: set JAVA_HOME=“C:\程序文件(x86)\Java\jdk1.8.0_131”

#17


0  

After hours of work around most of the solutions here, the problem was solved for me just by installing 32-bit JDK.

在围绕这里的大多数解决方案进行了数小时的工作之后,我只需安装32位的JDK就可以解决这个问题。

#1


620  

Find JDK Installation Directory

找到JDK安装目录

First you need to know the installation path for the Java Development Kit.

首先,您需要知道Java开发工具包的安装路径。

Open the default installation path for the JDK:

打开JDK的默认安装路径:

C:\Program Files\Java

There should be a subdirectory like:

应该有如下子目录:

C:\Program Files\Java\jdk1.6.0_10

Note: one has only to put the path to the jdk without /bin in the end (as suggested on a lot of places). e.g. C:\Java\jdk1.6.0_31 and NOT C:\Java\jdk1.6.0_31\bin !

注意:您只需将路径放置到jdk而最终没有/bin(正如在许多地方建议的那样)。\Java\jdk1.6.0_31\而不是C:\Java\jdk1.6.0_31\bin !


Set the JAVA_HOME Variable

设置JAVA_HOME变量

Once you have the JDK installation path:

一旦您有了JDK安装路径:

  1. Right-click the My Computer icon on your desktop and select Properties.
  2. 右键单击桌面的My Computer图标并选择Properties。
  3. Click the Advanced tab, then click the Environment Variables button.
  4. 单击Advanced选项卡,然后单击Environment Variables按钮。
  5. Under System Variables, click New.
  6. 在系统变量下,单击New。
  7. Enter the variable name as JAVA_HOME.
  8. 输入变量名JAVA_HOME。
  9. Enter the variable value as the installation path for the Java Development Kit.
  10. 输入变量值作为Java开发工具包的安装路径。
  11. Click OK.
  12. 单击OK。
  13. Click Apply Changes.
  14. 单击Apply变化。

Note: You might need to restart Windows

注意:您可能需要重新启动Windows

The complete article is here, on my blog: Setting JAVA_HOME Variable in Windows.

完整的文章在这里,在我的博客上:在Windows中设置JAVA_HOME变量。

Get Video Solution.

得到视频解决方案。

#2


142  

What worked for me was adding the %JAVA_HOME%\bin to the Path environment variable with the JAVA_HOME environment variable pointing to the jdk folder.

对我有用的是将%JAVA_HOME%\bin添加到Path环境变量中,JAVA_HOME环境变量指向jdk文件夹。

#3


113  

You have to first Install JDK in your system.

您必须首先在系统中安装JDK。

Set Java Home

设置Java回家

JAVA_HOME = C:\Program Files\Java\jdk1.7.0 [Location of your JDK Installation Directory]

JAVA_HOME = C:\Program Files\Java\jdk1.7.0(JDK安装目录的位置)

Once you have the JDK installation path:

一旦您有了JDK安装路径:

  • Right-click the My Computer icon on
  • 右键单击My Computer图标
  • Select Properties.
  • 选择Properties。
  • Click the Advanced system setting tab on left side of your screen
  • 单击屏幕左侧的高级系统设置选项卡
  • Aadvance Popup is open.
  • Aadvance弹出开放。
  • Click on Environment Variables button.
  • 单击“环境变量”按钮。

如何在Windows 7上设置java_home ?

  • Under System Variables, click New.
  • 在系统变量下,单击New。
  • Enter the variable name as JAVA_HOME.
  • 输入变量名JAVA_HOME。
  • Enter the variable value as the installation path for the Java Development Kit.
  • 输入变量值作为Java开发工具包的安装路径。
  • Click OK.
  • 单击OK。
  • Click Apply Changes.
  • 单击Apply变化。

Set JAVA Path under system variable

在系统变量下设置JAVA路径。

PATH= C:\Program Files\Java\jdk1.7.0; [Append Value with semi-colon]

路径= C:\Program Files\Java\ jdk1.7.0;(附加价值与分号)

如何在Windows 7上设置java_home ?

#4


22  

In cmd (temporarily for that cmd window):

在cmd中(临时用于cmd窗口):

set JAVA_HOME="C:\\....\java\jdk1.x.y_zz"

echo %JAVA_HOME%

set PATH=%PATH%;%JAVA_HOME%\bin

echo %PATH%

#5


16  

http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html

http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html

Control Panel > Java, Java tab, click the View button. In Runtime Parameters, put:

控制面板> Java, Java选项卡,点击查看按钮。在运行时参数,将:

-Djava.home=YOUR_PATH_HERE

Or when you execute Java you can add that command line switch to the command:

或者当您执行Java时,您可以将命令行切换添加到命令:

java -Djava.home=PATH SomeJavaApp

#6


14  

You need to set it to C:\Sun\SDK\jdk (Assuming that is where the JDK is installed - It is not the default) - Do not put the \bin in C:\Sun\SDK\jdk\bin.

您需要将它设置为C:\Sun\SDK\jdk(假设jdk就安装在那里——它不是默认设置)—不要将\bin放在C:\Sun\SDK\jdk\bin中。

If your app only runs when you are logged in as the current user then put it in the user variables - If it needs to run for all users on your system then put it in System variables.

如果你的应用程序只在你作为当前用户登录时才运行,那么就把它放在用户变量中——如果它需要为系统上的所有用户运行,那么就把它放在系统变量中。

You might also need to add %JAVA_HOME%\bin to the path also (Also it depends on whether you run it from just the user or from all users, including System)

您可能还需要将%JAVA_HOME%\bin添加到路径中(也取决于您是从用户还是从所有用户,包括系统中运行它)

#7


7  

This is the official solution for setting the Java environment from www.java.com - here.

这是在www.java.com -这里设置Java环境的官方解决方案。

There are solutions for Windows 7, Windows Vista, Windows XP, Linux/Solaris and other shells.

有针对Windows 7、Windows Vista、Windows XP、Linux/Solaris和其他shell的解决方案。


Example

Windows 7

  1. Select Computer from the Start menu
  2. 从“开始”菜单中选择“计算机”
  3. Choose System Properties from the context menu
  4. 从上下文菜单中选择系统属性
  5. Click Advanced system settings -> Advanced tab
  6. 点击高级系统设置->高级标签
  7. Click on Environment Variables, under System Variables, find PATH, and click on it.
  8. 单击系统变量下的环境变量,找到路径,并单击它。
  9. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
  10. 在“编辑”窗口中,通过将类的位置添加到“路径”的值来修改路径。如果没有项路径,可以选择添加一个新变量,并添加路径作为名称,添加类的位置作为值。
  11. Reopen Command prompt window, and run your Java code.
  12. 重新打开命令提示窗口,运行Java代码。

#8


6  

For those who are still stumped with this problem (I tried all the above suggestions) --

对于那些仍然被这个问题难住的人(我尝试了以上所有的建议)—

If you're on a 64-bit version of Windows and you've installed the 32-bit JDK, besides adjusting PATH variables, you may need to adjust registry variables, too.

如果您使用的是64位版本的Windows,并且安装了32位JDK,那么除了调整路径变量之外,您可能还需要调整注册表变量。

I was pulling my hair out, having correctly set my PATH variables -- still to no avail -- and then only finding "vacated" Java entries in my registry, seemingly a deadend of fixing the "misfiring" Java Runtime Environment.

我绞尽脑汁,正确地设置了路径变量(仍然没用),然后在我的注册表中只找到“空出”的Java条目,这似乎是修复“故障”Java运行时环境的一个死胡同。

By using Process Monitor to watch the program I was trying to get started, in order to sniff out where it was looking in the registry for Java (Runtime Environment), I triumphantly discovered that it's looking in the 32-bit version of registry entries, found in HKEY_LOCAL_MACHINE\SOFTWARE\**Wow6432Node**\JavaSoft\Java Runtime Environment.

通过使用Process Monitor监视我正在尝试启动的程序,为了找出它在注册表中查找Java(运行时环境)的位置,我成功地发现它正在查找注册表项的32位版本,在HKEY_LOCAL_MACHINE\SOFTWARE\* Wow6432Node* \* javask\ 32 node *\Java运行时环境中找到。

Within that key, you should find subkeys of different Java versions installed (past and/or present). Click on the subkey of the latest version (my subkey is currently 1.7.0_25, for example). After clicking on that subkey, you'll see registry string values listed on the right, and particularly, JavaHome and RuntimeLib. You need to modify the values of those two values to reflect the both the current folder and jvm.dll file, respectively.

在该键中,您应该找到安装了不同Java版本的子键(过去和/或现在)。单击最新版本的子键(例如,我的子键当前为1.7.0_25)。单击该子键之后,您将看到在右侧列出的注册表字符串值,尤其是JavaHome和RuntimeLib。您需要修改这两个值的值,以反映当前文件夹和jvm。分别dll文件。

For example, in my case, the values were (previously) respectively set at C:\Program Files (x86)\Java\jre7 and C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll which are nonexistent on my machine. I had to update these to the current folder and file of C:\Program Files (x86)\Java\jdk1.7.0_25\jre and C:\Program Files (x86)\Java\jdk1.7.0_25\jre\bin\client\jvm.dll.

例如,在我的例子中,价值观(以前)分别设置在C:\Program Files (x86)\Java\jre7 C:\Program Files (x86)\Java\jre7\bin\client\jvm.在我的机器上不存在的dll。我不得不更新这些当前的文件夹和文件C:\Program Files (x86)\Java\ jdk1.7.0_25 \ jre和C:\Program Files (x86)\Java\ jdk1.7.0_25 \ jre \ bin \ client \ jvm.dll。

Again, this will depend entirely on both what version of Java (JDK and/or JRE) you have installed -- 32 or 64-bit -- and what type of operating system you're on -- 32 or 64-bit. Just know that they're reflected in different locations within the registry (like the Wow6432Node for 32 bit applications, in my case with the 32-bit JDK installed on a 64-bit machine).

同样,这完全取决于您安装的Java版本(JDK和/或JRE)(32位或64位)以及您使用的操作系统类型(32位或64位)。只需知道它们反映在注册表中的不同位置(比如32位应用程序的Wow6432Node,在我的例子中是安装在64位机器上的32位JDK)。

Now that I've updated those two registry values, my program runs flawlessly, with no more hiccups or complaints about a missing Java Runtime Environment (stemming from the registry).

现在我已经更新了这两个注册表值,我的程序运行得非常完美,不再出现任何问题,也不再抱怨缺少Java运行时环境(来自注册表)。

#9


6  

One Image can fix this issue. 如何在Windows 7上设置java_home ?

一个图像可以解决这个问题。

For More

更多的

#10


5  

Windows 7

  1. Go to Control Panel\All Control Panel Items\User Accounts using Explorer (not Internet Explorer!)

    转到控制面板\所有控制面板项目\用户帐户使用资源管理器(不是Internet Explorer!)

    or

    • click on the Start button

      单击“开始”按钮

      如何在Windows 7上设置java_home ?

    • click on your picture

      点击你的照片

      如何在Windows 7上设置java_home ?

  2. Change my environment variables

    改变我的环境变量

    如何在Windows 7上设置java_home ?

  3. New...

    新…

    如何在Windows 7上设置java_home ?

    (if you don't have enough permissions to add it in the System variables section, add it to the User variables section)

    (如果您没有足够的权限将其添加到系统变量部分中,请将其添加到用户变量部分)

  4. Add JAVA_HOME as Variable name and the JDK location as Variable value > OK

    添加JAVA_HOME作为变量名,JDK位置作为变量值>

    如何在Windows 7上设置java_home ?

Test:

测试:

  • open a new console (cmd)
  • 打开一个新的控制台(cmd)
  • type set JAVA_HOME
    • expected output: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
    • 预期的输出:JAVA_HOME = C:\ Program Files \ Java \ jdk1.8.0_60
  • 类型设置JAVA_HOME期望输出:JAVA_HOME=C:\程序文件\Java\jdk1.8.0_60。

#11


4  

In Eclipse: Window->Preferences->Java->Installed JREs

在Eclipse中:窗口- >首选项- > Java - >安装jre

Use the search feature to make sure your latest Java installation is listed; then make sure it is the one that is checked. This should be a JDK not a JRE.

使用搜索功能确保列出了最新的Java安装;然后确保它是被检查的那个。这应该是一个JDK而不是JRE。

#12


4  

While adding your Java directory to your PATH variable, you might want to put it right at the beginning of it. I've had the problem, that putting the Java directory at the end of the PATH would not work. After checking, I've found java.exe in my Windows\System32 directory and it looks like the first one wins, when there are several files with the same name in your PATH...

在将Java目录添加到PATH变量时,您可能希望将它放在它的开头。我遇到了一个问题,将Java目录放在路径的末尾将不起作用。检查后,我找到了java。在我的Windows\System32目录下的exe,当您的路径中有几个文件名相同的文件时,它看起来是第一个。

#13


4  

We need to make a distinction between the two environment variables that are discussed here interchangeably. One is the JAVA_HOME variable. The other is the Path variable. Any process that references the JAVA_HOME variable is looking for the search path to the JDK, not the JRE. The use of JAVA_HOME variable is not meant for the Java compiler itself. The compiler is aware of its own location. The variable is meant for other software to more easily locate the compiler. This variable is typically used by IDE software in order to compile and build applications from Java source code. By contrast, the Windows CMD interpreter, and many other first and third party software references the Path variable, not the JAVA_HOME variable.

我们需要区分这里讨论的两个环境变量。一个是JAVA_HOME变量。另一个是路径变量。任何引用JAVA_HOME变量的进程都在寻找到JDK的搜索路径,而不是JRE。使用JAVA_HOME变量并不适合Java编译器本身。编译器知道自己的位置。该变量用于其他软件更容易地定位编译器。IDE软件通常使用这个变量,以便从Java源代码编译和构建应用程序。相比之下,Windows CMD解释器和其他许多第一和第三方软件引用的是Path变量,而不是JAVA_HOME变量。

Use case 1: Compiling from CMD

用例1:从CMD编译

So for instance, if you are not using any IDE software, and you just want to be able to compile from the CMD, independent of your current working directory, then what you want is to set the Path variable correctly. In your case, you don't even need the JAVA_HOME variable. Because CMD is using Path, not JAVA_HOME to locate the Java compiler.

例如,如果您不使用任何IDE软件,并且您只是希望能够从CMD编译,独立于当前工作目录,那么您需要的是正确地设置路径变量。在您的示例中,甚至不需要JAVA_HOME变量。因为CMD使用的是Path,而不是JAVA_HOME来定位Java编译器。

Use case 2: Compiling from IDE

用例2:从IDE编译

However, if you are using some IDE software, then you have to look at the documentation first of all. It may require JAVA_HOME to be set, but it may also use another variable name for the same purpose. The de-facto standard over the years has been JAVA_HOME, but this may not always be the case.

但是,如果您正在使用一些IDE软件,那么您必须首先查看文档。它可能需要设置JAVA_HOME,但它也可能出于相同的目的使用另一个变量名。多年来事实上的标准一直是JAVA_HOME,但情况可能并不总是如此。

Use case 3: Compiling from IDE and CMD

用例3:从IDE和CMD编译。

If in addition to the IDE software you also want to be able to compile from the CMD, independent of your current working directory, then in addition to the JAVA_HOME variable you may also need to append the JDK search path to the Path variable.

如果除了IDE软件之外,您还希望能够从CMD编译,独立于当前工作目录,那么除了JAVA_HOME变量之外,您可能还需要将JDK搜索路径附加到path变量。

JAVA_HOME vs. Path

JAVA_HOME与路径

If your problem relates to compiling Java, then you want to check the JAVA_HOME variable, and Path (where applicable). If your problem relates to running Java applications, then you want to check your Path variable.

如果您的问题与编译Java有关,那么您需要检查JAVA_HOME变量和路径(如适用)。如果您的问题与运行Java应用程序有关,那么您需要检查路径变量。

Path variable is used universally across all operating systems. Because it is defined by the system, and because it's the default variable that's used for locating the JRE, there is almost never any problem running Java applications. Especially not on Windows where the software installers usually set everything up for you. But if you are installing manually, the safest thing to do is perhaps to skip the JAVA_HOME variable altogether and just use the Path variable for everything, for both JDK and the JRE. Any recent version of an IDE software should be able to pick that up and use it.

路径变量在所有操作系统中通用。因为它是由系统定义的,而且由于它是用于定位JRE的默认变量,所以运行Java应用程序几乎没有任何问题。尤其是在Windows系统上,安装软件的人通常会为你设置好一切。但是,如果您手动安装,最安全的做法可能是完全跳过JAVA_HOME变量,并仅为JDK和JRE使用路径变量。任何一个IDE软件的最新版本都应该能够选择并使用它。

Symlinks

符号链接

Symbolic links may provide yet another way to reference the JDK search path by piggybacking one of the existing environment variables.

符号链接可能提供了另一种方法来引用JDK搜索路径,它支持现有的环境变量之一。

I am not sure about previous versions of Oracle/Sun JDK/JRE releases, but at least the installer for jdk1.8.0_74 appends the search path C:\ProgramData\Oracle\Java\javapath to the Path variable, and it puts it at the beginning of the string value. This directory contains symbolic links to the java.exe, javaw.exe and javaws.exe in the JRE directory.

我不确定Oracle/Sun JDK/JRE的以前版本,但是至少jdk1.8.0_74的安装程序将搜索路径C:\ProgramData\Oracle\Java\javapath附加到path变量中,并将其放在字符串值的开头。这个目录包含了java的符号链接。exe,javaw。exe和javaw。JRE目录中的exe。

So at least with the Java 8 JDK, and presumably the Java 8 JRE standalone, no environment variable configuration needs to be done for the JRE. As long as you use the installer package to set it up. There may be differences on your Windows installation however. Note that the Oracle JRE comes bundled with the JDK.

因此,至少对于Java 8 JDK,以及独立的Java 8 JRE,不需要为JRE做环境变量配置。只要您使用安装程序包来设置它。但是,您的Windows安装可能存在差异。注意,Oracle JRE附带了JDK。

If you ever find that your Java JDK configuration is using the wrong version of the compiler, or it appears to be working by magic, without being explicitly defined so (without casting the spell), then you may have a symlink somewhere in your environment variables. So you may want to check for symlink.

如果您发现您的Java JDK配置使用了错误的编译器版本,或者它似乎是通过魔法工作的,而没有显式地定义它(不使用拼写),那么您的环境变量中可能有一个符号链接。你可能想要检查symlink。

#14


3  

Run Eclipse as Administrator.

以管理员身份运行Eclipse。

That solved my problem. I'm still digging for the logic behind it.

这解决了我的问题。我还在寻找它背后的逻辑。

#15


2  

if you have not restarted your computer after installing jdk just restart your computer.

如果您在安装jdk后没有重启计算机,请重新启动计算机。

if you want to make a portable java and set path before using java, just make a batch file i explained below.

如果您想在使用java之前创建一个可移植的java并设置路径,只需创建一个我在下面解释过的批处理文件。

if you want to run this batch file when your computer start just put your batch file shortcut in startup folder. In windows 7 startup folder is "C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"

如果您想在计算机启动时运行此批处理文件,请将批处理文件快捷方式放在startup文件夹中。在windows 7启动文件夹是“C:\用户\应用程序\漫游微软\ windows \ windows \启动菜单\程序\启动”

make a batch file like this:

制作一个这样的批处理文件:

set Java_Home=C:\Program Files\Java\jdk1.8.0_11
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_11\bin

note: java_home and path are variables. you can make any variable as you wish. for example set amir=good_boy and you can see amir by %amir% or you can see java_home by %java_home%

注意:java_home和path是变量。你可以随心所欲地设置任何变量。例如,set amir=good_boy,你可以看到amir% amir%或者java_home% java_home%

#16


2  

goto Mycomputer(This PC) -> rightclick ->select properties -> Advanced system settings -> environment variables-> in system variables click "New" button and write JAVA_HOME in variable name and path C:\Program Files\Java\jdk1.8.0_131 were jdk is present in variable value-> click ok.

goto Mycomputer(PC)- > rightclick - >选择属性- >高级- >环境变量- >系统设置在系统变量单击“新”按钮,写JAVA_HOME变量名和路径C:\Program Files\Java\ jdk1.8.0_131是jdk中变量值- >单击ok。

close and reopen the command prompt after setting JAVA_HOME. Sometimes changes does not reflect in the cmd opened before setting the JAVA_HOME.

在设置JAVA_HOME之后关闭并重新打开命令提示符。有时更改不会反映在设置JAVA_HOME之前打开的cmd中。

you can also set JAVA_HOME through terminal itself: SET JAVA_HOME="C:\Program Files (x86)\Java\jdk1.8.0_131"

您还可以通过终端本身设置JAVA_HOME: set JAVA_HOME=“C:\程序文件(x86)\Java\jdk1.8.0_131”

#17


0  

After hours of work around most of the solutions here, the problem was solved for me just by installing 32-bit JDK.

在围绕这里的大多数解决方案进行了数小时的工作之后,我只需安装32位的JDK就可以解决这个问题。