简体   繁体   English

无法在Windows 8上更改Java版本

[英]Cannot change java version on Windows 8

I have jdk6 and jdk7 installed on my Windows 8 machine. 我在Windows 8计算机上安装了jdk6和jdk7。 The JAVA_HOME environment variable originally pointed to C:\\Program Files\\Java\\jre7. JAVA_HOME环境变量最初指向C:\\ Program Files \\ Java \\ jre7。

I am now trying to run a program under Java 1.6. 我现在正在尝试在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". 我将JAVA_HOME更改为C:\\ Program Files \\ Java \\ jre6,但是当我在命令提示符下键入java -version时,得到的是“ java version“ 1.7.0_25”。甚至删除了所有与Java相关的环境变量并修改了路径变量不包含任何对Java的引用。但是,当我键入java -version(应该失败)时,我得到“ java版本“ 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". 我还尝试将JAVA_HOME更改为“ C:\\ Program Files \\ Java \\ jdk1.6.0_45”,而java -versio仍然给我“ java版本“ 1.7.0_25””。

Does anyone know why I am unable to change the Java version to 1.6? 有谁知道为什么我无法将Java版本更改为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. JAVA_HOME变量放在%SystemRoot%\\system32一之前。 Windows installer adds java.exe file to Windows\\system32 directory. Windows安装程序将java.exe文件添加到Windows \\ system32目录。 And since it comes before JAVA_HOME, the executable from system32 is used. 并且由于它位于JAVA_HOME之前,因此使用了system32中的可执行文件。

(don't forget to restart console before checking again for java version) (不要忘了重新启动控制台,然后再次检查Java版本)

Edit: last java adds to PATH folder C:\\ProgramData\\Oracle\\Java\\javapath . 编辑:最后一个Java添加到PATH文件夹C:\\ProgramData\\Oracle\\Java\\javapath in my case it was on first position in PATH. 就我而言,它位于PATH的第一个位置。 That folder contains symlinks to java.exe javaw.exe and javaws.exe. 该文件夹包含指向java.exe javaw.exe和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 您可以删除C:\\ProgramData\\Oracle\\Java\\javapath并添加JAVA_HOME (或直接指向Java bin目录
  • you can change symlinks in C:\\ProgramData\\Oracle\\Java\\javapath to those pointing to right executables. 您可以将C:\\ProgramData\\Oracle\\Java\\javapath符号链接更改为指向正确的可执行文件的符号链接。

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. 为了在直接调用java时从终端调用正确的JVM,必须将%JAVA_HOME%/bin放在路径中可能包含java.exe实现的任何其他目录之前。

If you have installed a JVM using the Java installer, you may have a java.exe in your %SystemRoot%\\system32 . 如果使用Java安装程序安装了JVM,则%SystemRoot%\\system32可能有一个java.exe This one is just a dummy implementation that look at the registry and use the last JVM installed. 这只是一个虚拟实现,它查看注册表并使用最后安装的JVM。

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. 如果%SystemRoot%\\system32 java.exe ,并且未使用正确的JVM,则必须正确卸载所有JVM,或者将%JAVA_HOME%\\bin放在%SystemRoot%\\system32之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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