Hbase Java API连接错误



我正试图从java应用程序连接到Hbase,如下所示:

Configuration config = HBaseConfiguration.create();
    config.set("hbase.zookeeper.quorum", "localhost");
    config.set("hbase.zookeeper.property.clientPort", "2181");
    config.set("zookeeper.znode.parent", "/hbase-unsecure");
    config.set("hbase.client.retries.number", Integer.toString(0));
    config.set("zookeeper.session.timeout", Integer.toString(60000));
    config.set("zookeeper.recovery.retry", Integer.toString(0));
    Connection conn = ConnectionFactory.createConnection(config);
    TableName TABLE_NAME = TableName.valueOf("weblog");
    Table table = conn.getTable(TABLE_NAME);
    Result r = table.get(new Get(Bytes.toBytes("row1")));
    System.out.println(r);

我将应用程序构建到JAR中,但在集群上运行时使用:

hadoop jar hbaseConnect-0.0.1-SNAPSHOT.jar com.packagename.hbaseConnect.HbaseConnect

我得到以下错误:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
    at com.DigiMerket.hbaseConnect.HbaseConnect.main(HbaseConnect.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

我尝试在HADOOP-env中将HBASE_CLASSSPATH添加到HADOOP_CLASSPATH中,如下所示​帖子建议,但我得到了同样的错误。。

通过如下设置"HADOOP_CLASSPATH",然后在同一终端中运行HADOOP/hbase-jar:来解决问题

 export HADOOP_CLASSPATH="$HADOOP_CLASSPATH:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-client.jar:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-common.jar:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-protocol-1.1.2.2.3.4.0-3485.jar:.:" 

运行罐子

hadoop  jar  hbaseConnect-0.0.1-SNAPSHOT.jar com.packagename.hbaseConnect.HbaseConnect

日志会提示您运行依赖于其他jar的jar。像hbase-client.jar

mkdir类似于libs,并将依赖jar放入libs的目录中并使用此命令:java-Djava.ext.dirs=/xxxx/xxxx/lib-jar/xxx/xxxx/你的jar

希望这能帮助你。

相关内容

  • 没有找到相关文章

最新更新