这里写自定义目录标题
问题描述
运行 HBase,即执行 bin/start-hbase.sh
时报错 UnsupportedClassVersionError
:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/hadoop/hbase/util/GetJavaProperty : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
...
master running as process 2041. Stop it first.
原因分析
- 报错
UnsupportedClassVersionError
,为Java
版本不支持,一般是低版本JVM
不能运行高版本JDK
编译的代码。 - 报错提示
version 52.0
,代表JDK 8 的魔数
- 本地安装的
JDK 7
,故应替换为 8.
解决方式
更换 Java 版本(可能操作多项)
如果使用 alternative 配置的 Java,则可以使用这种方式更换版本:
[root@server5 ~]# alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/local/java/jdk1.8.0_181/bin/java
2 /usr/local/java/jdk1.7.0_80/bin/java
Enter to keep the current selection[+], or type selection number: 1
[root@server5 ~]# vi /etc/profile
# export JAVA_HOME=/usr/local/java/jdk1.7.0_80
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
[root@server5 ~]# vi ~/.bashrc
# export JAVA_HOME=/usr/local/java/jdk1.7.0_80
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
export PATH=$PATH:$JAVA_HOME/bin
关闭 HBase 进程
在更换版本后仍有移除报上述错误,并且最后一句为:
... master running as process 2041. Stop it first.
使用如下命令杀死进程,重新启动:
[root@server5 ~]# kill -9 xxxx # xxxx 为进程号
附:相关命令
alternatives 使用方式
使用 alternatives 可便捷地配置 Java 版本,并且切换方便。同理,也可用于其他命令。
[root@server5 ~]# alternatives
alternatives version 1.7.4 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage: alternatives --install <link> <name> <path> <priority>
[--initscript <service>]
[--family <family>]
[--slave <link> <name> <path>]*
alternatives --remove <name> <path>
alternatives --auto <name>
alternatives --config <name>
alternatives --display <name>
alternatives --set <name> <path>
alternatives --list
common options: --verbose --test --help --usage --version --keep-missing
--altdir <directory> --admindir <directory>
[root@server5 /]# alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_181/bin/java 2
[root@server5 /]# alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_181/bin/javac 2
[root@server5 /]# alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.8.0_181/bin/jar 2
[root@server5 /]#
[root@server5 /]# alternatives --set java /usr/local/java/jdk1.8.0_181/bin/java
[root@server5 /]# alternatives --set javac /usr/local/java/jdk1.8.0_181/bin/javac
[root@server5 /]# alternatives --set jar /usr/local/java/jdk1.8.0_181/bin/jar
[root@server5 ~]# alternatives --remove javc /usr/local/java/jdk1.7.0_80/bin/java
[root@server5 ~]# alternatives --remove javac /usr/local/java/jdk1.7.0_80/bin/javac
[root@server5 ~]# alternatives --remove jar /usr/local/java/jdk1.7.0_80/bin/jar