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

转到控制面板\所有控制面板项\用户帐户使用浏览器(不是Internet Explorer!) 或 点击开始按钮 点击你的图片 改变环境变量 新… (如果您没有足够的权限将其添加到系统变量部分,请将其添加到用户变量部分) 添加JAVA_HOME为变量名,添加JDK位置为变量值> OK

测试:

打开一个新的控制台(cmd) 输入set JAVA_HOME 期望输出:JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60

其他回答

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

更多的

您需要将其设置为C:\Sun\SDK\jdk(假设这是jdk的安装位置-这不是默认值)-不要将\bin放在C:\Sun\SDK\jdk\bin中。

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

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

以管理员身份运行Eclipse。

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

你可能想在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就解决了这个问题。