After upgrading to Java8, javac still shows 1.7

前端 未结 6 2132
一生所求
一生所求 2020-12-13 06:43

I\'m having issues upgrading from JDK 1.7 -> 1.8 on OSX. The upgrade has completed, but javac still returns 1.7 as the version.

I\'ve downloaded JDK 8_u5 from Oracl

相关标签:
6条回答
  • 2020-12-13 07:14

    If /usr/libexec/java_home -v 1.8.0_05 --exec javac -version returns the correct version, then your problem is with:

    /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
    

    With a privileged user execute:

    cd /System/Library/Frameworks/JavaVM.framework/Versions/
    rm CurrentJDK
    ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/ CurrentJDK
    

    Solution found in Mankeh Blog


    Also check this answer on Super User for dynamically switching JDK versions.


    Update: I guess I've found the culprit!

    Try this:

    rm -rf ~/Library/Java/Extensions
    sudo rm -rf /Library/Java/Extensions
    

    Solution found in: Java 1.7 on OSX 10.9.2 running as 1.5?

    0 讨论(0)
  • 2020-12-13 07:24

    For Windows users:

    It is possible, that you have to change your PATH variable. Try to set your "%JAVA_HOME%/bin" as the first entry in the PATH.

    So now it looks like this:

     PATH    C:\Program Files\anyprogram;C:\Program Files\...;%JAVA_HOME%\bin
    

    And you change it like this:

     PATH    %JAVA_HOME%\bin;C:\Program Files\anyprogram;C:\Program Files\...
    

    Reason: Any other Program initiates an other Java Version first.

    0 讨论(0)
  • 2020-12-13 07:27

    Maybe you can delete the standard .jar file which in your classpath. When i delete the jar in /Library/Java/Extensions, the problem will be solved. More info : Java compilation error: Mac

    0 讨论(0)
  • 2020-12-13 07:27

    Firstly, you need to download and then install the jdk8(http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)

    Secondly, do some check as follows: Does your system have a not-linked-for-shell use java 8 already? Try this in you terminal (yes, the apostrophes are important):

    $ '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version 
    

    if it shows " java version "1.8.0_131" " , and then you can go to next step.

    my screenshot

    Thirdly, edit the bash_profile:

    $ vi ~/.bash_profile 
    

    and type this:

    JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
    PATH=$JAVA_HOME/bin:$PATH
    CLASSPATH=.:$JAVA_HOME/lib
    export JAVA_HOME
    export CLASSPATH 
    

    save it and quit, then

    source ~/.bash_profile 
    

    After the above steps, and check the java version

    $ java -version
    java version "1.8.0_131"
    Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
    
    0 讨论(0)
  • 2020-12-13 07:33

    Just adding my own experience here, I installed jdk-8u131-macosx-x64 from Oracle. Everything worked perfectly. No JAVA_HOME environment variables were present or needed.

    mehboob$ javac -version
    javac 1.8.0_131
    
    mehboob$ java -version
    java version "1.8.0_131"
    Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
    

    The /System/Library showed this:

    mehboob$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions/
    total 64
    lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.4 -> CurrentJDK
    lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.4.2 -> CurrentJDK
    lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.5 -> CurrentJDK
    lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.5.0 -> CurrentJDK
    lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.6 -> CurrentJDK
    lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.6.0 -> CurrentJDK
    drwxr-xr-x  8 root  wheel  272 Sep  9  2014 A
    lrwxr-xr-x  1 root  wheel    1 Oct 17  2013 Current -> A
    lrwxr-xr-x  1 root  wheel   59 Oct 17  2013 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
    

    While the /Library/Java had this:

    mehboob$ ls -l /Library/Java/
    total 8
    drwxrwxr-x  2 root  admin   68 Oct 17  2013 Extensions
    lrwxr-xr-x  1 root  wheel   48 Oct 17  2013 Home -> /System/Library/Frameworks/JavaVM.framework/Home
    drwxr-xr-x  3 root  wheel  102 Jun  9 11:43 JavaVirtualMachines
    

    There was nothing in Extensions, while JavaVirtualMachines only had the jdk1.8.0_131.jdk folder.

    This shows that a default installation of JDK works properly with no extra configuration required.

    0 讨论(0)
  • 2020-12-13 07:36

    This is (most likely) a bug in the installation process of jre8.

    I am getting the exact same behaviour when navigating to my jre8 folder, which is the one which Windows (in my case) shows by default:

    • java version: 1.8.0, runtime environment 1.8.0-b132, hotspot 64-bit JVM 25.0-b70
    • javac version: 1.7.0_25

    When navigating to the jdk8 directory, it shows the following:

    • java version: 1.8.0, runtime environment 1.8.0-b132, hotspot 64-bit JVM 25.0-b70
    • javac version: 1.8.0

    I did just now notice though that the jre does never ship an javac, so this is an issue in the reference settings in the operating system then I guess.

    To fix it, you would need to manually fix the javac reference in your OS.

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