简体   繁体   中英

issue with java and environment variables on windows

I've got a curious problem. After installing java jdk 6u25 I tested the installation by typing java in the command prompt. Everything worked fine , the console displayed the usage options as expected. This was about 3 weeks ago - I recently reinstalled windows 7 on my machine- Now I would like to get started with the play framework and followed a tutorial. I got a new application with play new but couldn't use play run because of this:

play! 1.2.3, http://www.playframework.org

Ctrl+C to stop

Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly .

The funny thing is that typing java in the console still displays usage options and neither eclipse or netbeans complained about a missing jdk. Nevertheless I checked my environment variables and was surprised to find:

No reference to java at all.

Seriously I got no idea how the console, eclipse and netbeans found my java. As a first countermeasure I once again reinstalled java hoping that the installer might set the path correctly. It didn't. Now I would like your advise: Should I just create the JAVA_HOME variable ? If I do, will further versions of the jdk override the variable to point to the new version or will I have to change the variable manually everytime? What about eclipse and netbeans. I would guess that they have been downloaded with their "own" jdk. If I want to update java on my machine, will it update their versions, too ?

Update: I set the environment variable manually and restarted the pc. Now everything works fine but I would like to know what symbolic link is. Could you just give me a link in a comment or explain briefly ?

Eclipse and netbeans use a different way of finding your java installation than command line tools likes play, ant, maven, gradle etc.

IDEs may search your registry, guess default locations, or even have the JRE prepackaged with the installation.

Command-line tools usually rely on JAVA_HOME variable. And you have to set that manually.

Should I just create the JAVA_HOME variable ?

There are several tools that use that environment variable, so I'd recommend creating it.

If I do, will further versions of the jdk override the variable to point to the new version or will I have to change the variable manually everytime?

If you install your new Java version into the same folder (or if you create symbolic links), then no.

What about eclipse and netbeans. I would guess that they have been downloaded with their "own" jdk. If I want to update java on my machine, will it update their versions, too ?

That depends on whether the JDK is prebundled and how the configuration is done. I can't speak for Netbeans but in Eclipse, you could add this to your eclipse.ini :

-vm
C:/Java/jre/bin

Note that this is an example path to the bin folder. If you don't add versions there or use symbolic links (see above) then you'd not have to update the path when installing a new version.

It is possible that you have a (older?) java.exe in C:\\windows or other common directory. Make sure that the java you get on the command line is the one you think it is:

java -version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM