Java 如何在 Windows 上安装多个 JDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/886744/
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
How install multiple JDK on Windows?
提问by Eric Yung
I want to install JDK 1.5 and 1.6 on XP, is it possible? how to do it
我想在 XP 上安装 JDK 1.5 和 1.6,可以吗?怎么做
Also, I am using Eclipse how to setup using different JDK for different projects?
另外,我正在使用 Eclipse 如何为不同的项目设置使用不同的 JDK?
thanks.
谢谢。
采纳答案by Manrico Corazzi
You may install different JDKs easily: just specify different folders.
您可以轻松安装不同的 JDK:只需指定不同的文件夹。
You can setup the installed JDKs in Eclipse Window/Preferences/Installed JREs
您可以在 Eclipse Window/Preferences/Installed JREs 中设置已安装的 JDK
You can pick the JDK and Java version for every single project in Project/Properties/Java Compiler
您可以在Project/Properties/Java Compiler 中为每个项目选择 JDK 和 Java 版本
回答by graham.reeds
Why? There is an option (can't remember where exactly - right-click on your project) that allows you to set the target JDK level. I use this when developing GWT applications.
为什么?有一个选项(不记得确切位置 - 右键单击您的项目)允许您设置目标 JDK 级别。我在开发 GWT 应用程序时使用它。
回答by Osanda Deshan
I have solved this by creating batch files for different Java versions.
我通过为不同的 Java 版本创建批处理文件解决了这个问题。
- I have installed the Java versions I need to have
- Whenever, I need to use Java I run the appropriate batch file and set the environment variables to work with that Java version.
- 我已经安装了我需要的 Java 版本
- 每当我需要使用 Java 时,我都会运行适当的批处理文件并设置环境变量以使用该 Java 版本。
Java 8.bat
Java 8.bat
@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121
echo setting PATH
set PATH=%JAVA_HOME%\bin;%PATH%
echo Display java version
java -version
Java 10.bat
Java 10.bat
@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk-10.0.2
echo setting PATH
set PATH=%JAVA_HOME%\bin;%PATH%
echo Display java version
java -version