Mac启动Hive时报:Exception in thread “main“ java.lang.ClassCastException的解决办法

记一次诡异的问题:启动Hive时报:java.lang.ClassCastException

Mac安装Hive后命令行启动,然后报类型转换异常,如下图。
报错日志
检查jdk环境变量配置正确,尝试修改了hive可执行文件中的JAVA_HOME,依旧不行。

vim $(which hive)

#!/bin/bash
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home" HIVE_HOME="/usr/local/Cellar/hive/3.1.2_1/libexec" exec "/usr/local/Cellar/hive/3.1.2_1/libexec/bin/hive"  "$@"

但是排查方向是正确的,还是jdk指向路径的问题。
最后折腾了一个晚上,发现是hadoop-env.sh中的JAVA_HOME路径没有配置,我这里将其配置成绝对路径了,配置成${JAVA_HOME}也行。

cd /usr/local/Cellar/hadoop/3.2.1_1/libexec/etc/hadoop
vim hadoop-env.sh

###

# Technically, the only required environment variable is JAVA_HOME.
# All others are optional.  However, the defaults are probably not
# preferred.  Many sites configure these options outside of Hadoop,
# such as in /etc/profile.d

# The java implementation to use. By default, this environment
# variable is REQUIRED on ALL platforms except OS X!
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home

最后切记重启hadoop服务以生效:start-all.sh。
hive启动成功!
hive启动成功!如果有相同问题的小伙伴,希望我的随手记录能够帮到您!

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/apache-hive-2.3.5/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop-3.3.1/share/hadoop/common/lib/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap') at org.apache.hadoop.hive.ql.session.SessionState.<init>(SessionState.java:394) at org.apache.hadoop.hive.ql.session.SessionState.<init>(SessionState.java:370) at org.apache.hadoop.hive.cli.CliSessionState.<init>(CliSessionState.java:60) at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:708) at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:686) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.apache.hadoop.util.RunJar.run(RunJar.java:323) at org.apache.hadoop.util.RunJar.main(RunJar.java:236)
06-03
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值