How can I change Mac OS's default Java VM returned from /usr/libexec/java_home

后端 未结 12 747
刺人心
刺人心 2020-12-04 04:42

(Wasn\'t sure if this should go on SU... migration is certainly an option, but more programmers read questions here, so here goes).

I am running Mac OS X 10.8.4, and

12条回答
  •  醉酒成梦
    2020-12-04 05:26

    I've been there too and searched everywhere how /usr/libexec/java_home works but I couldn't find any information on how it determines the available Java Virtual Machines it lists.

    I've experimented a bit and I think it simply executes a ls /Library/Java/JavaVirtualMachines and then inspects the .//Contents/Info.plist of all runtimes it finds there.

    It then sorts them descending by the key JVMVersion contained in the Info.plist and by default it uses the first entry as its default JVM.

    I think the only thing we might do is to change the plist: sudo vi /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Info.plist and then modify the JVMVersion from 1.8.0 to something else that makes it sort it to the bottom instead of the top, like !1.8.0.

    Something like:

    
    
    
    
        ...
        
                ...
                JVMVersion
                !1.8.0   `
    

    and then it magically disappears from the top of the list:

    /usr/libexec/java_home -verbose
    Matching Java Virtual Machines (3):
        1.7.0_45, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
        1.7.0_09, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home
        !1.8.0, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    

    Now you will need to logout/login and then:

    java -version
    java version "1.7.0_45"
    

    :-)

    Of course I have no idea if something else breaks now or if the 1.8.0-ea version of java still works correctly.

    You probably should not do any of this but instead simply deinstall 1.8.0.

    However so far this has worked for me.

提交回复
热议问题