Java 7 64 bit on windows 7: how to switch java ver

2019-02-11 16:27发布

问题:

I need to switch from the installed java 7 at 64bit to the installed java 6 on my Windows 7 64bit OS but the usual procedure doesn't works. I tried to change the JAVA_HOME environment variable but when I type java -version, the system replies Java 7... How can I switch from different java versions?

Thank you.

回答1:

You need to switch the path environment variable too, to point before to the JRE bin directory. Also, I think modern versions of java place a copy of "java.exe" in the system32 directory of Windows, you'll need to remove them (or rename them, if you want to keep them as backups).



回答2:

JAVA_HOME is not used by java.exe.

Make sure to have the path of the Java 6 JRE's bin directory in the PATH environment variable, before the Java 7 JRE's one, and before windows system directory (system32).

Or you can use the full path of the java command:

c:\java6\bin\java com.foo.bar.Main


回答3:

Windows relies on PATH environment variable and not JAVA_HOME to lookup executables including the Java application launcher java.exe. While the JAVA_HOME environment variable may be used in the PATH environment variable, it need not be the case, so you must modify the PATH environment variable to use JAVA_HOME or the new Java 6 installation home.



回答4:

Since Java supports a "-version" command line option. You can use this to select a specific version to run, e.g.:

java -version:1.7 -jar [path to jar file] will run a jar application in java 1.7, if it is installed.

See Oracle's documentation here: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html