请问Java连接HBase报这个错怎么解决:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.security.authentication.util.KerberosUtil.hasKerberosTicket(Ljavax/security/auth/Subject;)Z
详细描述:
服务器环境:位于Ubuntu-16.04,Hadoop-2.8.0 HA集群,HBase-1.2.5
开发环境:Win7 64位,jar 都已经导入
代码:
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
public class TestHBase {
public static Configuration configuration;
public static Connection connection;
public static Admin admin;
public static void main(String[] args) throws IOException {
println("Start...");
init();
listTables();
close();
println("End...");
}
/**
* 查看已有表
*
* @throws IOException
*/
public static void listTables() {
HTableDescriptor hTableDescriptors[] = null;
try {
hTableDescriptors = admin.listTables();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (HTableDescriptor hTableDescriptor : hTableDescriptors) {
println(hTableDescriptor.getNameAsString());
}
}
/**
* 初始化链接
*/
public static void init() {
configuration = HBaseConfiguration.create();
//configuration.set("hadoop.home.dir","/home/hadoop/hadoop-home/hadoop-2.8.0/");
configuration.set("hbase.zookeeper.property.clientPort", "2181");
configuration.set("hbase.zookeeper.quorum", "172.16.0.240,172.16.0.241,172.16.0.242");
configuration.set("hbase.master", "hdfs://172.16.0.240:60000");
configuration.set("hbase.root.dir", "hdfs://172.16.0.240:9000/hbase");
try {
connection = ConnectionFactory.createConnection(configuration);
admin = connection.getAdmin();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 关闭连接
*/
public static void close() {
try {
if (null != admin) {
admin.close();
}
if (null != connection) {
connection.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
报错:
Start...
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/common-jars/hive/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/common-jars/hbase/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
11:47:59.807 DEBUG org.apache.hadoop.util.Shell 500 <clinit> - Failed to detect a valid hadoop home directory java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.
at org.apache.hadoop.util.Shell.checkHadoopHomeInner(Shell.java:448) ~[hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.Shell.checkHadoopHome(Shell.java:419) ~[hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:496) [hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:79) [hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.conf.Configuration.getBoolean(Configuration.java:1445) [hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:67) [hbase-common-1.1.1.jar:1.1.1]
at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:81) [hbase-common-1.1.1.jar:1.1.1]
at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:96) [hbase-common-1.1.1.jar:1.1.1]
at com.cherrish.hadoop.TestHBase2.init(TestHBase2.java:28) [bin/:?]
at com.cherrish.hadoop.TestHBase2.listTables(TestHBase2.java:107) [bin/:?]
at com.cherrish.hadoop.TestHBase2.main(TestHBase2.java:17) [bin/:?]
11:47:59.807 WARN org.apache.hadoop.util.Shell 673 <clinit> - Did not find winutils.exe: java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset. -see https://wiki.apache.org/hadoop/WindowsProblems
11:47:59.807 DEBUG org.apache.hadoop.util.Shell 675 <clinit> - Failed to find winutils.exe java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset. -see https://wiki.apache.org/hadoop/WindowsProblems
at org.apache.hadoop.util.Shell.fileNotFoundException(Shell.java:528) ~[hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.Shell.getHadoopHomeDir(Shell.java:549) ~[hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.Shell.getQualifiedBin(Shell.java:572) ~[hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:669) [hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:79) [hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.conf.Configuration.getBoolean(Configuration.java:1445) [hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:67) [hbase-common-1.1.1.jar:1.1.1]
at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:81) [hbase-common-1.1.1.jar:1.1.1]
at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:96) [hbase-common-1.1.1.jar:1.1.1]
at com.cherrish.hadoop.TestHBase2.init(TestHBase2.java:28) [bin/:?]
at com.cherrish.hadoop.TestHBase2.listTables(TestHBase2.java:107) [bin/:?]
at com.cherrish.hadoop.TestHBase2.main(TestHBase2.java:17) [bin/:?]
Caused by: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.
at org.apache.hadoop.util.Shell.checkHadoopHomeInner(Shell.java:448) ~[hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.Shell.checkHadoopHome(Shell.java:419) ~[hadoop-common-2.8.0.jar:?]
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:496) ~[hadoop-common-2.8.0.jar:?]
... 8 more
11:47:59.946 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginSuccess with annotation @org.apache.hadoop.metrics2.annotation.Metric(about=, sampleName=Ops, always=false, type=DEFAULT, value=[Rate of successful kerberos logins and latency (milliseconds)], valueName=Time)
11:47:59.963 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginFailure with annotation @org.apache.hadoop.metrics2.annotation.Metric(about=, sampleName=Ops, always=false, type=DEFAULT, value=[Rate of failed kerberos logins and latency (milliseconds)], valueName=Time)
11:47:59.963 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.getGroups with annotation @org.apache.hadoop.metrics2.annotation.Metric(about=, sampleName=Ops, always=false, type=DEFAULT, value=[GetGroups], valueName=Time)
11:47:59.964 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field private org.apache.hadoop.metrics2.lib.MutableGaugeLong org.apache.hadoop.security.UserGroupInformation$UgiMetrics.renewalFailuresTotal with annotation @org.apache.hadoop.metrics2.annotation.Metric(about=, sampleName=Ops, always=false, type=DEFAULT, value=[Renewal failures since startup], valueName=Time)
11:47:59.965 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field private org.apache.hadoop.metrics2.lib.MutableGaugeInt org.apache.hadoop.security.UserGroupInformation$UgiMetrics.renewalFailures with annotation @org.apache.hadoop.metrics2.annotation.Metric(about=, sampleName=Ops, always=false, type=DEFAULT, value=[Renewal failures since last successful login], valueName=Time)
11:47:59.966 DEBUG org.apache.hadoop.metrics2.impl.MetricsSystemImpl 231 register - UgiMetrics, User and group related metrics
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
11:48:00.153 DEBUG org.apache.hadoop.security.authentication.util.KerberosName 88 <clinit> - Kerberos krb5 configuration not found, setting default realm to empty
11:48:00.153 DEBUG org.apache.hadoop.security.Groups 448 getUserToGroupsMappingService - Creating new Groups object
11:48:00.153 DEBUG org.apache.hadoop.util.NativeCodeLoader 46 <clinit> - Trying to load the custom-built native-hadoop library...
11:48:00.171 DEBUG org.apache.hadoop.util.NativeCodeLoader 55 <clinit> - Failed to load native-hadoop with error: java.lang.UnsatisfiedLinkError: no hadoop in java.library.path
11:48:00.171 DEBUG org.apache.hadoop.util.NativeCodeLoader 56 <clinit> - java.library.path=D:\env\java\jre8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/env/java/jre8/bin/server;D:/env/java/jre8/bin;D:/env/java/jre8/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;D:\env\java\jdk1.7.0_25\bin;D:\env\java\jdk1.7.0_25\jre\bin;D:\env\maven\apache-maven-3.3.9\bin;D:\Program Files (x86)\nodejs\;D:\env\Android\sdk\tools;D:\env\Android\sdk\platform-tools;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;D:\Program Files (x86)\TortoiseSVN\bin;D:\env\MySQL\MySQL Server 5.6\bin;D:\env\MySQL\MySQL Utilities 1.3.6\;D:\Program Files (x86)\MATLAB\MATLAB Runtime\v901\runtime\win64;D:\tools\MATLAB7\bin\win32;C:\Program Files\Git\cmd;D:\env\Python\Python35-32;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;D:\env\Go\bin;C:\Users\admin\AppData\Roaming\npm;;D:\tools\eclipse-jee-luna\eclipse;;.
11:48:00.172 WARN org.apache.hadoop.util.NativeCodeLoader 62 <clinit> - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
11:48:00.173 DEBUG org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback 41 <init> - Falling back to shell based
11:48:00.175 DEBUG org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback 45 <init> - Group mapping impl=org.apache.hadoop.security.ShellBasedUnixGroupsMapping
11:48:00.203 DEBUG org.apache.hadoop.security.Groups 152 <init> - Group mapping impl=org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback; cacheTimeout=300000; warningDeltaMs=5000
11:48:00.218 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 239 login - hadoop login
11:48:00.218 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 174 commit - hadoop login commit
11:48:00.218 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 204 commit - using local user:NTUserPrincipal: admin
11:48:00.218 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 210 commit - Using user: "NTUserPrincipal: admin" with name admin
11:48:00.218 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 220 commit - User entry: "admin"
11:48:00.218 DEBUG org.apache.hadoop.security.UserGroupInformation 841 loginUserFromSubject - Assuming keytab is managed externally since logged in from subject.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.security.authentication.util.KerberosUtil.hasKerberosTicket(Ljavax/security/auth/Subject;)Z
at org.apache.hadoop.security.UserGroupInformation.<init>(UserGroupInformation.java:652)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:843)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:802)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:675)
at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:286)
at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:282)
at org.apache.hadoop.hbase.security.User.getCurrent(User.java:185)
at org.apache.hadoop.hbase.security.UserProvider.getCurrent(UserProvider.java:88)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:215)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119)
at com.cherrish.hadoop.TestHBase2.init(TestHBase2.java:36)
at com.cherrish.hadoop.TestHBase2.listTables(TestHBase2.java:107)
at com.cherrish.hadoop.TestHBase2.main(TestHBase2.java:17)
谢谢!
补充:如果编译成jar包到Hadoop 集群上去执行也报错:
Caused by: java.lang.NoSuchMethodError: org.apache.hadoop.security.authentication.util.KerberosUtil.hasKerberosTicket(Ljavax/security/auth/Subject;)Z
Start...
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:rsrc:log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:rsrc:slf4j-log4j12-1.7.5.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]
14:31:37.238 DEBUG org.apache.hadoop.util.Shell 793 isSetsidSupported - setsid exited with exit code 0
14:31:37.609 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginSuccess with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[Rate of successful kerberos logins and latency (milliseconds)], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
14:31:37.629 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginFailure with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[Rate of failed kerberos logins and latency (milliseconds)], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
14:31:37.630 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.getGroups with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[GetGroups], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
14:31:37.631 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field private org.apache.hadoop.metrics2.lib.MutableGaugeLong org.apache.hadoop.security.UserGroupInformation$UgiMetrics.renewalFailuresTotal with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[Renewal failures since startup], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
14:31:37.632 DEBUG org.apache.hadoop.metrics2.lib.MutableMetricsFactory 42 newForField - field private org.apache.hadoop.metrics2.lib.MutableGaugeInt org.apache.hadoop.security.UserGroupInformation$UgiMetrics.renewalFailures with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[Renewal failures since last successful login], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
14:31:37.637 DEBUG org.apache.hadoop.metrics2.impl.MetricsSystemImpl 231 register - UgiMetrics, User and group related metrics
14:31:41.171 DEBUG org.apache.hadoop.security.authentication.util.KerberosName 88 <clinit> - Kerberos krb5 configuration not found, setting default realm to empty
14:31:41.195 DEBUG org.apache.hadoop.security.Groups 448 getUserToGroupsMappingService - Creating new Groups object
14:31:41.212 DEBUG org.apache.hadoop.util.NativeCodeLoader 46 <clinit> - Trying to load the custom-built native-hadoop library...
14:31:41.214 DEBUG org.apache.hadoop.util.NativeCodeLoader 55 <clinit> - Failed to load native-hadoop with error: java.lang.UnsatisfiedLinkError: no hadoop in java.library.path
14:31:41.215 DEBUG org.apache.hadoop.util.NativeCodeLoader 56 <clinit> - java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
14:31:41.216 WARN org.apache.hadoop.util.NativeCodeLoader 62 <clinit> - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14:31:41.424 DEBUG org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback 41 <init> - Falling back to shell based
14:31:41.429 DEBUG org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback 45 <init> - Group mapping impl=org.apache.hadoop.security.ShellBasedUnixGroupsMapping
14:31:41.528 DEBUG org.apache.hadoop.security.Groups 152 <init> - Group mapping impl=org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback; cacheTimeout=300000; warningDeltaMs=5000
14:31:41.534 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 239 login - hadoop login
14:31:41.535 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 174 commit - hadoop login commit
14:31:41.543 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 204 commit - using local user:UnixPrincipal: hadoop
14:31:41.544 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 210 commit - Using user: "UnixPrincipal: hadoop" with name hadoop
14:31:41.545 DEBUG org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule 220 commit - User entry: "hadoop"
14:31:41.545 DEBUG org.apache.hadoop.security.UserGroupInformation 841 loginUserFromSubject - Assuming keytab is managed externally since logged in from subject.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoSuchMethodError: org.apache.hadoop.security.authentication.util.KerberosUtil.hasKerberosTicket(Ljavax/security/auth/Subject;)Z
at org.apache.hadoop.security.UserGroupInformation.<init>(UserGroupInformation.java:652)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:843)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:802)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:675)
at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:286)
at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:282)
at org.apache.hadoop.hbase.security.User.getCurrent(User.java:185)
at org.apache.hadoop.hbase.security.UserProvider.getCurrent(UserProvider.java:88)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:215)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119)
at com.cherrish.hadoop.TestHBase2.init(TestHBase2.java:36)
at com.cherrish.hadoop.TestHBase2.listTables(TestHBase2.java:107)
at com.cherrish.hadoop.TestHBase2.main(TestHBase2.java:17)
... 5 more
没设置HADOOP_HOME?
hadoop/hbase集群上的环境都设置好了,需要在本地开发环境设置吗?你要把你的jar包放到hadoop集群上去执行,才能读取到hadoop的那几个xml配置文件,找到hadoop节点
jar去重后仍报错,Causedby:java.lang.ClassNotFoundException:org.apache.htrace.Tracehtrace-core-3.0.4.jar包已经导入jar包都去重了,然后还是报错:10:13:36.584DEBUGorg.apache.zookeeper.ClientCnxn102<clinit>-zookeeper.disableAutoWatchResetisfalsejava.io.IOException:java.lang.reflect.InvocationTargetExceptionatorg.回复 @驛路梨花醉美:NoSuchMethod通常是你混合了多个版本的jar包,你检查下你的项目依赖放到hadoop集群上执行,还是报错:Causedby:java.lang.NoSuchMethodError:org.apache.hadoop.security.authentication.util.KerberosUtil.hasKerberosTicket(Ljavax/security/auth/Subject;)Z版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。