java.lang.ClassNotFoundException: io.netty.channel.EventLoopGroup hbase报错

hbase client依赖最少的jar包

java.lang.ClassNotFoundException: io.netty.channel.EventLoopGroup hbase报错_第1张图片

代码片

// 声明静态配置
    static Configuration conf = null;
    static {
        conf = HBaseConfiguration.create();  
        conf.set("hbase.zookeeper.property.clientPort", "2181");  
        conf.set("hbase.zookeeper.quorum", "vm20602");  
        conf.set("hbase.master", "172.16.2.78:16000");  
    }

    /*
     * 创建表
     *
     * @tableName 表名
     *
     * @family 列族列表
     */
    public static void creatTable(String tableName, String[] family)
            throws Exception {
        HBaseAdmin admin = new HBaseAdmin(conf);
        HTableDescriptor desc = new HTableDescriptor
        (TableName.valueOf(tableName));
        for (int i = 0; i < family.length; i++) {
            desc.addFamily(new HColumnDescriptor
            (family[i]).setMaxVersions(10));
        }
        if (admin.tableExists(tableName)) {
            System.out.println("table Exists!");
        } else {
            admin.createTable(desc);
            System.out.println("create table Success!");
        }
        Closeables.close(admin,false);
    }

报错

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.io.IOException: java.lang.reflect.InvocationTargetException
    at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:240)
    at org.apache.hadoop.hbase.client.ConnectionManager.createConnection(ConnectionManager.java:410)
    at org.apache.hadoop.hbase.client.ConnectionManager.createConnection(ConnectionManager.java:403)
    at org.apache.hadoop.hbase.client.ConnectionManager.getConnectionInternal(ConnectionManager.java:281)
    at org.apache.hadoop.hbase.client.HBaseAdmin.(HBaseAdmin.java:202)
    at test.HbaseClient.creatTable(HbaseClient.java:42)
    at test.HbaseClient.main(HbaseClient.java:330)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:238)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: io/netty/channel/EventLoopGroup
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:266)
    at org.apache.hadoop.conf.Configuration.getClassByNameOrNull(Configuration.java:1844)
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1809)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1903)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1929)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.(ConnectionManager.java:631)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: io.netty.channel.EventLoopGroup
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 18 more

解决办法:
将 netty-3.2.4.Final.jar 包换成netty-all-4.0.23.Final.jar
这里写图片描述

你可能感兴趣的:(hbase)