Windows ignores JAVA_HOME: how to set JDK as default?

前端 未结 14 2823
感动是毒
感动是毒 2020-11-27 11:30

How do I persuade Windows to use the JDK instead of a JRE?

This question has been asked before, here and elsewhere:

How do I set the default Java installatio

相关标签:
14条回答
  • 2020-11-27 12:00

    I had the same issue. I have a bunch of Java versions installed and for some reason Java 1.7 was being used instead of Java 1.6, even though I specified in the path to use 1.6 (C:\jdk1.6.0_45_32\bin).

    I had to move the path of the JDK I wanted to use (1.6) to be the first entry in the PATH environment variable to make sure Windows uses 1.6 instead of 1.7.

    So, for example, the PATH environment variable before was:

    C:\Program Files (x86);...<other entries>;C:\dev\ant181\bin;C:\jdk1.6.0_45_32\bin
    

    and after I moved the jdk to be first, it worked:

    C:\jdk1.6.0_45_32\bin;C:\Program Files (x86);...<other entries>;C:\dev\ant181\bin
    

    I guess the Windows installer of Java 1.7 installed it to some other directory already in the PATH, thus getting used first instead of the specified custom PATH entry C:\jdk1.6.0_45_32\bin;

    0 讨论(0)
  • 2020-11-27 12:01

    Suppose you have install JDK 10 after JDK 8 and in the system environment variable set path like "C:\ProgramData\Oracle\Java\javapath" then Java version control by this path. it will ignore JAVA_HOME even jdk 1.8 path set here So remove "C:\ProgramData\Oracle\Java\javapath" in path to get effect of JAVA_HOME path

    0 讨论(0)
  • 2020-11-27 12:04

    On Windows, the java executable uses the Windows Registry to locate the default version of Java to run.

    The copy of java.exe to run is found by using the PATH environment variable. Unless you take steps to change this, by default a copy will be found in the Windows directory. Since this copy isn't in a Java runtime directory, it locates one by looking at the registry.

    So, you either need to modify the registry, or put the version of Java you want before the Windows directory in your PATH.

    0 讨论(0)
  • 2020-11-27 12:05

    After struggling with this issue for some time and researching about it, I finally managed to solve it following these steps:

    1) install jdk version 12
    2) Create new variable in systems variable
    3) Name it as JAVA_HOME and give jdk installation path
    4) add this variable in path and move it to top.
    5) go to C:\Program Files (86)\Common Files\Oracle\Java\javapath and replace java.exe and javaw.exe with the corresponding files with the same names from the pathtojavajdk/bin folder

    Finally, I checked the default version of java in cmd with "java -version" and it worked!

    0 讨论(0)
  • 2020-11-27 12:08

    Set Path environment variable to your desired jdk/bin directory

    0 讨论(0)
  • 2020-11-27 12:12

    I had Java 7 and 8 installed and I want to redirect to java 7 but the java version in my cmd prompt window shows Java 8.
    Added Java 7 bin directory path (C:\Program Files\Java\jdk1.7.0_10\bin) to PATH variable at the end, but did not work out and shows Java 8. So I changed the Java 7 path to the starting of the path value and it worked.
    Opened a new cmd prompt window and checked my java version and now it shows Java 7

    0 讨论(0)
提交回复
热议问题