我在控制面板的“系统”中的环境变量中创建了两个新变量,一个用于用户变量,一个用于系统变量。它们都被命名为JAVA_HOME,并且都指向
C: \ Sun jdk \ SDK \ \ bin
但出于某种原因,我在运行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
我该如何解决这个问题?
这是从www.java.com -此处设置Java环境的官方解决方案。
有针对Windows 7、Windows Vista、Windows XP、Linux/Solaris和其他shell的解决方案。
例子
Windows 7
Select Computer from the Start menu
Choose System Properties from the context menu
Click Advanced system settings -> Advanced tab
Click on Environment Variables, under System Variables, find PATH, and click on it.
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.
Reopen Command prompt window, and run your Java code.
这是从www.java.com -此处设置Java环境的官方解决方案。
有针对Windows 7、Windows Vista、Windows XP、Linux/Solaris和其他shell的解决方案。
例子
Windows 7
Select Computer from the Start menu
Choose System Properties from the context menu
Click Advanced system settings -> Advanced tab
Click on Environment Variables, under System Variables, find PATH, and click on it.
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.
Reopen Command prompt window, and run your Java code.
查找JDK安装目录
首先,您需要知道Java Development Kit的安装路径。
打开JDK默认安装路径:
C:\Program Files\Java
应该有这样的子目录:
C:\Program Files\Java\jdk1.8.0_172
注意:最后只需要放置jdk的路径而不需要/bin(正如在很多地方所建议的那样)。C:\Java\jdk1.8.0_172\bin !
设置JAVA_HOME变量
有了JDK安装路径后:
右键单击桌面上的“我的电脑”图标,选择“属性”。
单击高级选项卡,然后单击环境变量按钮。
在“系统变量”下单击“新建”。
输入变量名JAVA_HOME。
输入变量值作为Java Development Kit的安装路径。
单击OK。
单击“应用更改”。
注意:您可能需要重新启动Windows
完整的文章在我的博客上:在Windows中设置JAVA_HOME变量。
如果安装JDK后没有重新启动计算机,请重新启动计算机。
如果你想在使用Java之前制作一个可移植的Java并设置路径,只需制作一个我下面解释的批处理文件。
如果您想在计算机启动时运行此批处理文件,只需将批处理文件快捷方式放在启动文件夹中。在windows 7的启动文件夹是“C:\Users\user\AppData\漫游\Microsoft\ windows \开始菜单\程序\启动”
做一个这样的批处理文件:
set Java_Home=C:\Program Files\Java\jdk1.8.0_11
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_11\bin
注意:
Java_home和path是变量。你可以随意设置任何变量。
例如,设置amir=good_boy,你可以通过%amir%看到amir,或者通过%java_home%看到java_home