Caused by: java.lang.ClassNotFoundException: org.apache.zookeeper.KeeperException

匿名 (未验证) 提交于 2019-12-03 02:28:01

问题:

When I run a JAVA program(can not new HTable) under the Eclipse IDE, i got following errors:

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 

Where is this wrong?

回答1:

Try this

I fixed this by editing the file "/usr/local/hbase-0.94.1/conf/hbase-env.sh" and adding the element "export HBASE_CLASSPATH=/usr/local/hbase-0.94.1/lib".

The zookeeper JAR is located in the HBase installation at "/usr/local/hbase-0.94.1/lib".



回答2:

Just include the zookeeper jar file in your build path located in HBASE. It should solve your problem.



回答3:

Your class might not get access via your code try using distributed cache and load the jar files, use the link to set the configurations : https://hadoop.apache.org/docs/r2.4.1/api/org/apache/hadoop/filecache/DistributedCache.html



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!