Resolving version conflict between java and javac on Ubuntu

后端 未结 5 1598
故里飘歌
故里飘歌 2021-02-01 06:09

I have a problem with my compiled Java application on Ubuntu. It throws UnsupportedClassVersionError. I am compiling with a higher JDK version than the one that is

相关标签:
5条回答
  • 2021-02-01 06:24

    This is what you want Java and Ubuntu. I have the same config basically, but I am switching back and forth from Glassfish and Java7. Take a look and try setting up your Java env in a similar fashion

    0 讨论(0)
  • 2021-02-01 06:27

    Type following command in terminal :

      sudo update-alternatives --config java
    

    It will ask you for:

    There are 2 choices for the alternative java (providing /usr/bin/java).

      Selection      Path                                            Priority   Status
    
        0           /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode
    
        1           /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
    
        2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java  1051      manual mode
    
    
      Press enter to keep the current choice[*], or type selection number:
    

    I enter 2 as I want to use java 1.7.0_21

    0 讨论(0)
  • 2021-02-01 06:43

    You will also need to do:

    sudo update-alternatives --config javac
    

    Select the desired java compiler from the list provided. For example on Centos 5

    There are 2 programs which provide 'javac'.
    Selection    Command
    -----------------------------------------------
    1           /usr/lib/jvm/java-1.6.0-openjdk/bin/javac
    *+ 2        /usr/lib/jvm/java-1.7.0-openjdk/bin/javac
    
    0 讨论(0)
  • 2021-02-01 06:45

    I have added and installed alternatives for Java and Javac with below steps it work for me :

    Steps 1: Add the Java and Javac alternatives :

    Command to add Javac:

    sudo update-alternatives --install "/usr/bin/java" "java" "/opt/amazon-jdk-11/bin/java" 1 
    

    i.e : "/opt/amazon-jdk-11/bin/javac" this the new path of java

    sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/amazon-jdk-11/bin/javac" 1
    

    i.e : /opt/amazon-jdk-11/bin/javac is the new path of javac

    Steps 2: Installed the Java and Javac alternatives :

    sudo update-alternatives --config javac
    sudo update-alternatives --config javac
    

    Once you enter above command you will able to see screen like below you can select your number that you want to configure java.

    I have selected " 1 "int the list as I wanted to installed "/opt/amazon-jdk-11/bin/java" as my javac.

    Verify your Java alternative installation is successful or not with below commands :

    which javac and which java you will able to see screen like below :

    0 讨论(0)
  • 2021-02-01 06:46

    Run either of the following to locate where the location is of that

    javac 1.7.0_147
    

    being used as follows:

    whereis javac
    

    or

     locate javac
    

    or

    find javac
    

    Then once you found the directory, symbolically and forcefully link the bin contents to /usr/bin:

    sudo ln -f -s [put location here]/bin/* /usr/bin
    
    0 讨论(0)
提交回复
热议问题