我在控制面板的“系统”中的环境变量中创建了两个新变量,一个用于用户变量,一个用于系统变量。它们都被命名为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

我该如何解决这个问题?


当前回答

你可能想在Windows/System32文件夹中找到以下文件: ——java.exe ——javaw.exe ——javaws.exe

Because, the path variable is including these files, you can get a headache trying to figure out why the java -version or javac -version keeps pointing to the old JAVA_HOME: rename those files, take out the extension with an underscore, for instance. And then, you only will have to create the JAVA_HOME variable, add it to the path variable (e.g., %JAVA_HOME%) and append the "\bin" particle. This way you need to only change the JAVA_HOME variable pointing to different JRE or JDK and have multiple installations of java just by setting JAVA_HOME.

这也意味着最好手动安装Java,不需要安装程序,这样您就可以随意使用它。

其他回答

以管理员身份运行Eclipse。

这解决了我的问题。我还在研究背后的逻辑。

goto Mycomputer(这台PC) ->右键单击->选择属性->高级系统设置->环境变量->在系统变量中单击“新建”按钮并在变量名称和路径C:\Program Files\Java\ jdk1.8.0_131 were jdk在变量值中存在->单击确定。

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

你也可以通过终端设置JAVA_HOME: SET JAVA_HOME="C:\Program Files (x86)\Java\jdk1.8.0_131"

如果安装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

你可能想在Windows/System32文件夹中找到以下文件: ——java.exe ——javaw.exe ——javaws.exe

Because, the path variable is including these files, you can get a headache trying to figure out why the java -version or javac -version keeps pointing to the old JAVA_HOME: rename those files, take out the extension with an underscore, for instance. And then, you only will have to create the JAVA_HOME variable, add it to the path variable (e.g., %JAVA_HOME%) and append the "\bin" particle. This way you need to only change the JAVA_HOME variable pointing to different JRE or JDK and have multiple installations of java just by setting JAVA_HOME.

这也意味着最好手动安装Java,不需要安装程序,这样您就可以随意使用它。

在对这里的大多数解决方案进行了数小时的研究之后,我只需要安装32位JDK就解决了这个问题。