How do I set the default Java installation/runtime (Windows)?

前端 未结 9 1375
迷失自我
迷失自我 2020-12-08 00:19

I\'m in the situation where I\'ve installed the JDK, but I can\'t run applets in browsers (I may not have installed the JRE).

However, when I install the JRE, it clo

9条回答
  •  遥遥无期
    2020-12-08 00:56

    After many attempts, I found the junction approach more convenient. This is very similar on how this problem is solved in linux.

    Basically it consists of having a link between c:\tools\java\default and the actual version of java you want to use as default in your system.


    How to set it:

    1. Download junction and make sure to put it in your PATH environment variable
    2. Set your environment this way: - PATH pointing to ONLY to this jre c:\tools\java\default\bin - JAVA_HOME pointing to `c:\tools\java\default
    3. Store all your jre-s in one folder like (if you do that in your Program FIles folder you may encounter some
      • C:\tools\Java\JRE_1.6
      • C:\tools\Java\JRE_1.7
      • C:\tools\Java\JRE_1.8
    4. Open a command prompt and cd to C:\tools\Java\
    5. Execute junction default JRE_1.6

    This will create a junction (which is more or less like a symbolic link in linux) between C:\tools\java\default and C:\tools\java\JRE_1.6

    In this way you will always have your default java in c:\tools\java\default.

    If you then need to change your default java to the 1.8 version you just need to execute

    junction -d default
    junction default JRE_1.8 
    

    Then you can have batch files to do that without command prompt like set_jdk8.bat set_jdk7.bat

    As suggested from @СӏаџԁеМаятіи

    EDIT: From windows vista, you can use mklink /J default JRE_1.8

提交回复
热议问题