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

在cmd中(暂时用于该cmd窗口):

set JAVA_HOME="C:\\....\java\jdk1.x.y_zz"

echo %JAVA_HOME%

set PATH=%PATH%;%JAVA_HOME%\bin

echo %PATH%

http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html

控制面板> Java, Java选项卡,单击“查看”按钮。在运行时参数中,放入:

-Djava.home=YOUR_PATH_HERE

或者当你执行Java时,你可以在命令中添加命令行开关:

java -Djava.home=PATH SomeJavaApp

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"

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