我在控制面板的“系统”中的环境变量中创建了两个新变量,一个用于用户变量,一个用于系统变量。两者都被命名为 JAVA_HOME 并且都指向
C:\Sun\SDK\jdk\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
我该如何解决这个问题?
查找 JDK 安装目录
首先你需要知道Java开发工具包的安装路径。
打开JDK的默认安装路径:
C:\Program Files\Java
应该有一个像这样的子目录:
C:\Program Files\Java\jdk1.8.0_172
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.8.0_172 and NOT C:\Java\jdk1.8.0_172\bin !
设置 JAVA_HOME 变量
一旦你有了 JDK 安装路径:
- 右键单击桌面上的我的电脑图标,然后选择属性。
- 点击高级标签,然后点击环境变量按钮。
- 在系统变量下,点击新建。
- 输入变量名称为JAVA_HOME。
- 输入变量值作为 Java 开发工具包的安装路径。
- 点击确定。
- 点击应用更改。
Note: You might need to restart Windows
完整的文章在这里,在我的博客上:Setting JAVA_HOME Variable in Windows .
我是一名优秀的程序员,十分优秀!