引起:java.lang.ClassNotFoundException:org.apache.zookeeper.KeeperException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19150604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Caused by: java.lang.ClassNotFoundException: org.apache.zookeeper.KeeperException
提问by user2840940
When I run a JAVA program(can not new HTable) under the Eclipse IDE, i got following errors:
当我在 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.run(URLClassLoader.java:366)
at java.net.URLClassLoader.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?
这是哪里错了?
回答by Raymond Ramirez
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".
我通过编辑文件“/usr/local/hbase-0.94.1/conf/hbase-env.sh”并添加元素“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".
zookeeper JAR 位于 HBase 安装中的“/usr/local/hbase-0.94.1/lib”。
回答by Mayank Agarwal
Just include the zookeeper jar file in your build path located in HBASE. It should solve your problem.
只需在位于 HBASE 的构建路径中包含 zookeeper jar 文件。它应该可以解决您的问题。
回答by Anup Ash
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
您的课程可能无法通过您的代码访问尝试使用分布式缓存并加载 jar 文件,使用链接设置配置:https: //hadoop.apache.org/docs/r2.4.1/api/org/apache/hadoop /filecache/DistributedCache.html