我进入控制面板“系统”中的环境变量并创建了两个新变量,一个用于用户变量,一个用于系统变量。两者都被命名为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 .
关于java - 如何在 Windows 7 上设置 java_home?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46365788/