远程链接HBase调试报错:Exception in thread "main" java.lang.ExceptionInInitializerError

一、问题描述

1.环境

CentOS6,CDH5.7.0,hbase-1.2.0-cdh5.7.0

2.报错描述

外部连接hbase服务器,在创建admin时报错:

String nameSpace = "Test";
        String tbName = "student";
        String colFamily = "info";
        // 1.读取配置文件
        //的hbase-default.xml,也可以把hbase-site.xml放到resources中
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.rootdir","hdfs://hadoop01:8020/hbase");
        conf.set("hbase.zookeeper.quorum","hadoop01");
        conf.set("hbase.zookeeper.property.clientPort","2181");

        Connection connection;
        connection = ConnectionFactory.createConnection(conf);

        // 2.创建一个管理员,管理表格的创建和删除
//        HBaseAdmin admin = new HBaseAdmin(conf);
        Admin admin=connection.getAdmin();

报错:

19/04/10 09:03:20 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.apache.hadoop.hbase.client.HConnectionKey.(HConnectionKey.java:72)
	at org.apache.hadoop.hbase.client.ConnectionManager.getConnectionInternal(ConnectionManager.java:300)
	at org.apache.hadoop.hbase.client.HBaseAdmin.(HBaseAdmin.java:231)
	at Hbase.HbaseUtils.main(HbaseUtils.java:24)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:131)
	at org.apache.hadoop.security.Groups.(Groups.java:78)
	at org.apache.hadoop.security.Groups.(Groups.java:74)
	at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:303)
	at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:288)
	at org.apache.hadoop.hbase.security.UserProvider.(UserProvider.java:56)
	... 4 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:129)
	... 9 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
	at org.apache.hadoop.util.PerformanceAdvisory.(PerformanceAdvisory.java:23)
	at org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback.(JniBasedUnixGroupsMappingWithFallback.java:41)
	... 14 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 16 more

二、问题原因

把hbase-site.xml都放入了resources里面,而且使用的是CDH,所以兼容性基本排除。经过几天煎熬,竟然发现是少protobuf包,当把protobuf加入pom依赖,世界瞬间变美好了!

三、解决办法

添加pom依赖



    com.google.protobuf
    protobuf-java
    2.5.0

(大数据坑,一步一个踩!)

你可能感兴趣的:(idea,hbase)