在 Windows 中安装和切换 java 7 和 java 8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35153270/
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
install and switch between java 7 and java 8 in windows
提问by Aman Agrawal
I am on widows and also using eclipse. Currently I am using java 7. Now I want to use java 8. but i cannot uninstall java 7 as some of my old projects are working in java 7.
我在寡妇身上,也在使用日食。目前我正在使用 java 7。现在我想使用 java 8。但我无法卸载 java 7,因为我的一些旧项目正在 java 7 中工作。
So how can I install both java version at same time and switch between these versions.
那么如何同时安装两个 java 版本并在这些版本之间切换。
I want only some particular projects will use java 8.
我希望只有一些特定的项目会使用 java 8。
采纳答案by Kunal_89
Install both JDKs in your system and for any project if you want to use jdk 1.8. Do this
如果您想使用 jdk 1.8,请在您的系统和任何项目中安装这两个 JDK。做这个
Right click on that project->Properties->java complier->set compliance level to 1.8
回答by Shiva
Well after installing both JDK 7 & JDK 8, There are two scenarios.
安装 JDK 7 和 JDK 8 后,有两种情况。
1) If you are using Eclipse to run your program
1) 如果你使用 Eclipse 来运行你的程序
In Eclipse just go to project->Properties->java complier->set compliance level to 1.8 or 1.7 accordingly
在 Eclipse 中,只需转到 project->Properties->java 编译器->相应地将合规级别设置为 1.8 或 1.7
2) If you are running your program using Command Prompt
2) 如果您使用命令提示符运行程序
In this case, you have to enter following commands before compiling your program
在这种情况下,您必须在编译程序之前输入以下命令
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_102
set PATH=C:\Program Files\Java\jdk1.8.0_102\bin;%PATH%
java -version
you can also make a batch file of the same. just copy and paste to notepad and save it with the .bat extension
您也可以制作相同的批处理文件。只需复制并粘贴到记事本并使用 .bat 扩展名保存
回答by Christian Constantinescu
Create a script that changes the JAVA_HOME environment accordingly, for example:
创建一个脚本来相应地更改 JAVA_HOME 环境,例如:
@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.6.0_11\bin;%PATH%
echo Display java version
java -version
Source: https://blogs.oracle.com/pranav/entry/switch_between_different_jdk_v
来源:https: //blogs.oracle.com/pranav/entry/switch_between_different_jdk_v
回答by gascon95
If you are using Eclipse, you can set the compiler preferences with the Java version you want to use for every project.
如果您使用的是 Eclipse,则可以使用要用于每个项目的 Java 版本来设置编译器首选项。
Go to Window -> Preferences -> Java -> Compiler
and there you can change the Java version.
去Window -> Preferences -> Java -> Compiler
那里你可以改变Java版本。
This way, you can update your PC to Java 8 and you'll have no problem with the older projects.
这样,您可以将 PC 更新到 Java 8,并且旧项目不会有任何问题。