How to set java_home on Windows 7?

2018-12-31 01:29发布

I went to the Environment Variables in 'System' in the control panel and made two new variables, one for user variables and one for system variables. Both were named JAVA_HOME and both pointing to

C:\Sun\SDK\jdk\bin

But for some reason, I still get the below error when running a Java command...

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

How can I fix this problem?

17条回答
君临天下
2楼-- · 2018-12-31 02:26

Windows 7

  1. Go to Control Panel\All Control Panel Items\User Accounts using Explorer (not Internet Explorer!)

    or

    • click on the Start button

      start

    • click on your picture

      clickOnPhoto

  2. Change my environment variables

    Change my environment variables

  3. New...

    new

    (if you don't have enough permissions to add it in the System variables section, add it to the User variables section)

  4. Add JAVA_HOME as Variable name and the JDK location as Variable value > OK

    edit system variable ok

Test:

  • open a new console (cmd)
  • type set JAVA_HOME
    • expected output: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
查看更多
刘海飞了
3楼-- · 2018-12-31 02:26

goto Mycomputer(This PC) -> rightclick ->select properties -> Advanced system settings -> environment variables-> in system variables click "New" button and write JAVA_HOME in variable name and path C:\Program Files\Java\jdk1.8.0_131 were jdk is present in variable value-> click ok.

close and reopen the command prompt after setting JAVA_HOME. Sometimes changes does not reflect in the cmd opened before setting the JAVA_HOME.

you can also set JAVA_HOME through terminal itself: SET JAVA_HOME="C:\Program Files (x86)\Java\jdk1.8.0_131"

查看更多
情到深处是孤独
4楼-- · 2018-12-31 02:27

What worked for me was adding the %JAVA_HOME%\bin to the Path environment variable with the JAVA_HOME environment variable pointing to the jdk folder.

查看更多
查无此人
5楼-- · 2018-12-31 02:27

In cmd (temporarily for that cmd window):

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

echo %JAVA_HOME%

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

echo %PATH%
查看更多
萌妹纸的霸气范
6楼-- · 2018-12-31 02:28

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

Control Panel > Java, Java tab, click the View button. In Runtime Parameters, put:

-Djava.home=YOUR_PATH_HERE

Or when you execute Java you can add that command line switch to the command:

java -Djava.home=PATH SomeJavaApp
查看更多
登录 后发表回答