简体   繁体   中英

Cannot change java version on Windows 8

I have jdk6 and jdk7 installed on my Windows 8 machine. The JAVA_HOME environment variable originally pointed to C:\\Program Files\\Java\\jre7.

I am now trying to run a program under Java 1.6. I changed JAVA_HOME to C:\\Program Files\\Java\\jre6 but when I type java -version at the command prompt I get "java version "1.7.0_25". I have even deleted all environment variables related to Java and modified the path variable to not include any reference to Java. However, when I type java -version (which should fail) I get "java version "1.7.0_25".

I have also tried changing JAVA_HOME to "C:\\Program Files\\Java\\jdk1.6.0_45" and java -versio still gives me "java version "1.7.0_25".

Does anyone know why I am unable to change the Java version to 1.6?

My current path is:

c:\Program Files (x86)\Intel\iCLS Client\;c:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Live\Shared;%JAVA_HOME%\bin;%M2_HOME%\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;%OPEN_SSL%\bin

Put JAVA_HOME variable before %SystemRoot%\\system32 one. Windows installer adds java.exe file to Windows\\system32 directory. And since it comes before JAVA_HOME, the executable from system32 is used.

(don't forget to restart console before checking again for java version)

Edit: last java adds to PATH folder C:\\ProgramData\\Oracle\\Java\\javapath . in my case it was on first position in PATH. That folder contains symlinks to java.exe javaw.exe and javaws.exe. Now you have two options.

  • you can delete C:\\ProgramData\\Oracle\\Java\\javapath and add JAVA_HOME (or point directly do java bin directory
  • you can change symlinks in C:\\ProgramData\\Oracle\\Java\\javapath to those pointing to right executables.

In order to have the right JVM called from the terminal when you call java directly, you'll have to put %JAVA_HOME%/bin in your path before any other directory that may contain a java.exe implementation.

If you have installed a JVM using the Java installer, you may have a java.exe in your %SystemRoot%\\system32 . This one is just a dummy implementation that look at the registry and use the last JVM installed.

If you have a java.exe in your %SystemRoot%\\system32 and it's not using the right JVM, you'll either have to correctly uninstall all JVM or to put %JAVA_HOME%\\bin before %SystemRoot%\\system32 in your path.

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