如果安装了 Java 8,则无法使用 Java 7 安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23877735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot use Java 7 installation if Java 8 is installed
提问by Sebastien Diot
I normally still use Java 7 for all my coding projects (it's a company "politics" issue), but I installed Java 8 for one third-party project I am contributing to. Now, it seems I cannot have Java 8 installed in Windows 7 x64, and still use Java 7 by default:
我通常仍然将 Java 7 用于我所有的编码项目(这是一个公司的“”问题),但我为我正在参与的一个第三方项目安装了 Java 8。现在,我似乎无法在 Windows 7 x64 中安装 Java 8,并且默认情况下仍然使用 Java 7:
C:\>"%JAVA_HOME%\bin\java.exe" -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
C:\>java.exe -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
As you can see, JAVA_HOME is completely ignored.
如您所见,JAVA_HOME 完全被忽略。
I also have Java in the path, using "%JAVA_HOME%\bin", which resolve correctly to Java 7 when I check the path in a DOS box, but it still makes no difference.
我在路径中也有 Java,使用“%JAVA_HOME%\bin”,当我在 DOS 框中检查路径时,它正确解析为 Java 7,但它仍然没有区别。
I checked in the "Java Control Panel" (not sure if this affects the default command-line Java version). Under the "Java" tab, the "View..." button, you get to see "registered" Java versions. I can add all the versions under the "User" tab, but under "System" there is only Java 8, and no way to change it.
我检查了“Java 控制面板”(不确定这是否会影响默认的命令行 Java 版本)。在“Java”选项卡下的“查看...”按钮下,您可以看到“已注册”的 Java 版本。我可以在“用户”选项卡下添加所有版本,但在“系统”下只有 Java 8,无法更改。
Am I missing something, or did Oracle just make it impossible to use Java 7, unless I de-install Java 8? I don't want to have to specify the "source" and "target" everywhere, and I don't even know if it is possible for me to specify it everywhere, where Java is used.
我是否遗漏了什么,或者 Oracle 是否只是让我无法使用 Java 7,除非我卸载 Java 8?我不想在任何地方都指定“源”和“目标”,我什至不知道是否可以在任何使用 Java 的地方指定它。
EDIT: What I did is I de-installed all Java. Then installed the latest Java7 (both 86 and x64), and then the latest Java8 (both 86 and x64). After I did that, I noticed that the x64 JDK was gone. It seems Java8 killed it. So I re-installed the JDK 7 x64, afterthe JDK 8 x64. Still, JDK7 x64 did not seem to "replace" the "java.exe" which is copied into the "Windows" directory itself (I assume THAT is the problem).
编辑:我所做的是卸载了所有 Java。然后安装了最新的 Java7(86 和 x64),然后是最新的 Java8(86 和 x64)。在我这样做之后,我注意到 x64 JDK不见了。似乎Java8杀死了它。所以我在 JDK 8 x64之后重新安装了 JDK 7 x64。尽管如此,JDK7 x64 似乎并没有“替换”复制到“Windows”目录本身的“java.exe”(我认为这就是问题所在)。
采纳答案by Peter Lawrey
Windows and Unix both find programs using their PATH
environment variable. You have an java.exe
in your Windows\System32
which is appearing before your "preferred" version of Java.
Windows 和 Unix 都使用它们的PATH
环境变量来查找程序。你有一个java.exe
在你Windows\System32
这是之前的Java你的“首选”的版本出现。
Change the PATH to be the one you need, or specify the full path when you need a different version.
将 PATH 更改为您需要的路径,或者在需要不同版本时指定完整路径。
回答by RealHowTo
You can select the JRE version from the command line with the -version: option.
您可以使用 -version: 选项从命令行选择 JRE 版本。
> java -version:"1.7" MyClass
should select the 1.7 JRE if installed properly.
如果安装正确,应该选择 1.7 JRE。
The list of the properly installed JRE is in the registry, see the key :
正确安装的 JRE 列表在注册表中,请参阅密钥:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment (32bit)
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment (64bit)
You can set the "CurrentVersion" there if you want a different default version than the latest.
如果您想要与最新版本不同的默认版本,您可以在此处设置“CurrentVersion”。
See http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#options
请参阅http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#options
Don't modify your PATH to point to a particuliar JRE, let the special java.exe in Windows/system32 do the job.
不要修改您的 PATH 以指向特定的 JRE,让 Windows/system32 中的特殊 java.exe 来完成这项工作。
回答by Mohammad-Hossein Jamali
When you install jdk8 it adds an entry like this
当您安装 jdk8 时,它会添加一个这样的条目
C:\ProgramData\Oracle\Java\javapath
C:\ProgramData\Oracle\Java\javapath
to beginning of your PATHenvironment variable, removing this entry should resolve your problem.
到PATH环境变量的开头,删除此条目应该可以解决您的问题。
回答by Alex
2 Steps
2 步
1
1
Change registry key **HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion**
to point to 1.7
将注册表项更改**HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion**
为指向 1.7
2
2
Copy java.exe,javaw.exe and javaws.exe
from your java 1.7 version to Windows\System32
folder
(Since the corresponding files of java 1.8 are already there, you might have to overwrite with admin permissions)
java.exe,javaw.exe and javaws.exe
从您的 java 1.7 版本复制到Windows\System32
文件夹(由于 java 1.8 的相应文件已经存在,您可能需要使用管理员权限覆盖)
3
3
(OOps actually not required 3rd step )
Open a newcmd window and check
java -version
(OOps 实际上不需要第三步)打开一个新的cmd 窗口并检查
java -version
回答by Sergio
Looks like you have to check where in your PATH is located your JAVA_HOME variable, the PATH is evaluated from left to right. A tip for you is to do all your Java system variables configuration at the beginning of your PATH.
看起来您必须检查 PATH 中 JAVA_HOME 变量的位置,从左到右评估 PATH。给您的提示是在 PATH 的开头进行所有 Java 系统变量配置。
PATH = %M2_HOME%\bin;%JAVA_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;...
Probably that's why after doing this:
可能这就是为什么这样做之后:
- java -version
you are getting this:
你得到这个:
- java version "1.8.0_05"
because there are other areas in your PATH that are pointing to other java.exe, for example C:\Windows\System32 or C:\ProgramData\Oracle\Java\javapath etc.
因为您的 PATH 中还有其他区域指向其他 java.exe,例如 C:\Windows\System32 或 C:\ProgramData\Oracle\Java\javapath 等。
回答by A Joshi
I had to make 2 changes for it to work:
我必须进行 2 处更改才能使其正常工作:
- Changed the Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'to 1.7 from 1.8
- The Java 8 installation adds a new entry to the PATH environment variable 'C:\ProgramData\Oracle\Java\javapath'. I removed this entry from the PATH.
- 将注册表项'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'从 1.8 更改为 1.7
- Java 8 安装向 PATH 环境变量'C:\ProgramData\Oracle\Java\javapath'添加了一个新条目。我从 PATH 中删除了这个条目。