How can I change the Java Runtime Version on Windows (7)?

后端 未结 8 736
后悔当初
后悔当初 2020-12-07 10:02

How can I change the Java Runtime Version on Windows.

I installed Java 7 for some tests, and now I need the old java6 as system default, but I don\'t want to un

8条回答
  •  伪装坚强ぢ
    2020-12-07 10:15

    I use to work on UNIX-like machines, but recently I have had to do some work with Java on a Windows 7 machine. I have had that problem and this is the I've solved it. It has worked right for me so I hope it can be used for whoever who may have this problem in the future.

    These steps are exposed considering a default Java installation on drive C. You should change what it is necessary in case your installation is not a default one.

    Change Java default VM on Windows 7

    Suppose we have installed Java 8 but for whatever reason we want to keep with Java 7.

    1- Start a cmd as administrator

    2- Go to C:\ProgramData\Oracle\Java

    3- Rename the current directory javapath to javapath_. E.g.: rename javapath javapath_1.8

    4- Create a javapath_ directory. E.g.: mkdir javapath_1.7

    5- cd into it and create the following links:

    cd javapath_1.7
    mklink java.exe "C:\Program Files\Java\jre7\bin\java.exe"
    mklink javaw.exe "C:\Program Files\Java\jre7\bin\javaw.exe"
    mklink javaws.exe "C:\Program Files\Java\jre7\bin\javaws.exe"
    

    6- cd out and create a directory link javapath pointing to the desired javapath. E.g.: mklink /D javapath javapath_1.7

    7- Open the register and change the key HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion to have the value 1.7

    At this point if you execute java -version you should see that you are using java version 1.7:

    java version "1.7.0_71"
    Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
    

    8- Finally it is a good idea to create the environment variable JAVA_HOME. To do that I create a directory link named CurrentVersion in C:\Program Files\Java pointing to the Java version I'm interested in. E.g.:

    cd C:\Program Files\Java\
    mklink /D CurrentVersion .\jdk1.7.0_71
    

    9- And once this is done:

    • Right click My Computer and select Properties.
    • On the Advanced tab, select Environment Variables, and then edit/create JAVA_HOME to point to where the JDK software is located, in that case, C:\Program Files\Java\CurrentVersion

提交回复
热议问题