java执行报错
“Exception in thread "main" java.lang.UnsupportedClassVersionError: xxx : Unsupported major.minor version 51.0”
原因是java编译和运行使用的jdk版本不一致:
$ whereis java
java: /usr/bin/java
$ ll /usr/bin/java*
lrwxrwxrwx 1 root root 22 Jul 10 2012 /usr/bin/java -> /etc/alternatives/java*
lrwxrwxrwx 1 root root 23 Jul 10 2012 /usr/bin/javac -> /etc/alternatives/javac*
lrwxrwxrwx 1 root root 25 Jul 10 2012 /usr/bin/javadoc -> /etc/alternatives/javadoc*
lrwxrwxrwx 1 root root 23 Jul 10 2012 /usr/bin/javah -> /etc/alternatives/javah*
lrwxrwxrwx 1 root root 23 Jul 10 2012 /usr/bin/javap -> /etc/alternatives/javap*
lrwxrwxrwx 1 root root 24 Jun 14 16:20 /usr/bin/javaws -> /etc/alternatives/javaws*
$ ll /etc/alternatives/java*
lrwxrwxrwx 1 root root 46 Jun 14 16:20 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java*
lrwxrwxrwx 1 root root 56 Jun 14 16:20 /etc/alternatives/java.1.gz -> /usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz
lrwxrwxrwx 1 root root 43 Jul 10 2012 /etc/alternatives/javac -> /usr/lib/jvm/java-7-openjdk-amd64/bin/javac*
lrwxrwxrwx 1 root root 53 Jul 10 2012 /etc/alternatives/javac.1.gz -> /usr/lib/jvm/java-7-openjdk-amd64/man/man1/javac.1.gz
在安装新的软件时系统环境被修改了,改回1.7。
sudo rm /etc/alternatives/java
sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java /etc/alternatives/java
或装回JDK6,linux一些软件还不支持JDK7.
-----------------------------------------
通过rpm安装的jdk,java默认路径还原:
lrwxrwxrwx 1 root root 26 May 25 10:52 /usr/bin/java -> /usr/java/default/bin/java
lrwxrwxrwx 1 root root 27 May 25 10:52 /usr/bin/javac -> /usr/java/default/bin/javac
lrwxrwxrwx 1 root root 29 May 25 10:52 /usr/bin/javadoc -> /usr/java/default/bin/javadoc
lrwxrwxrwx 1 root root 28 May 25 10:52 /usr/bin/javaws -> /usr/java/default/bin/javaws