Aman Agrawal
Aman Agrawal

Reputation: 95

install and switch between java 7 and java 8 in windows

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.

So how can I install both java version at same time and switch between these versions.

I want only some particular projects will use java 8.

Upvotes: 3

Views: 19292

Answers (4)

Create a script that changes the JAVA_HOME environment accordingly, for example:

@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

Upvotes: 4

Shiva
Shiva

Reputation: 143

Well after installing both JDK 7 & JDK 8, There are two scenarios.

1) If you are using Eclipse to run your program

In Eclipse just go to project->Properties->java complier->set compliance level to 1.8 or 1.7 accordingly

2) If you are running your program using Command Prompt

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

Upvotes: 8

Kunal_89
Kunal_89

Reputation: 309

Install both JDKs in your system and for any project if you want to use jdk 1.8. Do this

Right click on that project->Properties->java complier->set compliance level to 1.8

Upvotes: 2

gascon95
gascon95

Reputation: 115

If you are using Eclipse, you can set the compiler preferences with the Java version you want to use for every project.

Go to Window -> Preferences -> Java -> Compiler and there you can change the Java version.

This way, you can update your PC to Java 8 and you'll have no problem with the older projects.

Upvotes: 0

Related Questions