简体   繁体   中英

How install multiple JDK on Windows?

I want to install JDK 1.5 and 1.6 on XP, is it possible? how to do it

Also, I am using Eclipse how to setup using different JDK for different projects?

thanks.

You may install different JDKs easily: just specify different folders.

You can setup the installed JDKs in Eclipse Window/Preferences/Installed JREs

You can pick the JDK and Java version for every single project in Project/Properties/Java Compiler

I have solved this by creating batch files for different Java versions.

  1. I have installed the Java versions I need to have
  2. Whenever, I need to use Java I run the appropriate batch file and set the environment variables to work with that Java version.

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

@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

Try using sdkman . Even though the installing on Windows is a bit 'tricky' but there are several options.

https://sdkman.io/install

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.

There was a big mess with different incompatible JDK and JRE from 90s when Java was created and still this problem exists. The main rule is when you type in console:

java -version

and

javac -version

the result should be the same then you sure both JRE and JDK (JSDK) are compatible, so when you compile you can rut it without any problems.

JAVA_HOME and PATH are essential for many console applications and some GUI tools might use those variables as well but often is possible to alter default settings in GUI application instead of messing with environment variables. Also CLASSPATH still sometimes are used as well, however better use ANT as compiler than javac directly.

You can install multiple JDK and JRE but each one should to have its own separate folder, the default should be usually ok.

Worth mentioning that every JDK have JRE included and it instal in separate folder and as separate APP in Windows Control Panel -> Applications to be more confusing, so basically developer will never have to download and install JRE. Do not use Java update application which might cause problems after update some apps might not work, just do it manually.

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