jueves, 19 de febrero de 2015

Java7 and Java8 Cohabitation on Windows

You can have both Java7 and Java8 living in your Windows box and use one of them each time you are required to.

The following steps provide the guide to setup your local machine to use the java version you want, I assumed that you already had Java7 and just installed Java8:
  1. Go to C:\ProgramData\Oracle\Java\javapath and rename (you can also remove) the java*.exe files to some other names different than the original ones.
  2. Ensure that you path variable in your environment variables doesn't contain the C:\ProgramData\Oracle\Java\javapath path.
  3. To use java7, create a ''Java7_CMD.bat'' file containing the following lines:

  4. title CMD_JAVA7
    set JAVA_HOME=C:\Java\jdk1.7.0_55
    set PATH=%PATH%;%JAVA_HOME%\bin

    Set JAVA_HOME to your own path.

  5. Test you .bat file by executing it and running the following commands:
  6. C:\Users\Mauricio Fernandez\Desktop>java -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:\Users\Mauricio Fernandez\Desktop>javac -version
    javac 1.7.0_55

  7. Repeat steps 3 and 4 to create a "Java8_CMD.bat" file for Java8. Don't forget to set the properly paths and title.
  8. From now you just want to run the properly .bat file to get a command line window compatible with the java version you need.

That's it!