我在控制面板的“系统”中的环境变量中创建了两个新变量,一个用于用户变量,一个用于系统变量。它们都被命名为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
我该如何解决这个问题?
http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html
控制面板> Java, Java选项卡,单击“查看”按钮。在运行时参数中,放入:
-Djava.home=YOUR_PATH_HERE
或者当你执行Java时,你可以在命令中添加命令行开关:
java -Djava.home=PATH SomeJavaApp
你可能想在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,不需要安装程序,这样您就可以随意使用它。