原因:java.lang.classnotfoundexception:org.apache.zookeeper.keeperexception

xjreopfe  于 2021-06-03  发布在  Hadoop
关注(0)|答案(3)|浏览(1177)

在eclipse ide下运行java程序(不能新建htable)时,出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/zookeeperKeeperException
at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:185)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:154)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:132)
at HBaseConnector.main(HBaseConnector.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.zookeeper.KeeperException
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;

public class HBaseConnector {
    public static void main(String[] args) throws IOException {
    Configuration config = HBaseConfiguration.create();
    HTable table = new HTable(config, "myLittleHBaseTable");
    ...
}

--------------
used jar files:
hbase-0.94.6-cdh4.3.0.jar
zookeeper-3.4.5-cdh4.3.0-tests.jar
lf4j-log4j12-1.7.5.jar
commons-configuration-1.9.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
commons-lang-2.6.jar
hadoop-core-0.20.0.jar

哪里不对?

yruzcnhs

yruzcnhs1#

您的类可能无法通过您的代码访问请尝试使用分布式缓存并加载jar文件,使用链接设置配置:https://hadoop.apache.org/docs/r2.4.1/api/org/apache/hadoop/filecache/distributedcache.html

46qrfjad

46qrfjad2#

试试这个
我通过编辑文件“/usr/local/hbase-0.94.1/conf/hbase env.sh”并添加元素“export hbase\u classpath=/usr/local/hbase-0.94.1/lib”修复了这个问题。
zookeeper jar位于hbase安装中的“/usr/local/hbase-0.94.1/lib”。

j1dl9f46

j1dl9f463#

只需在hbase中的构建路径中包含zookeeper jar文件。它应该能解决你的问题。

相关问题