我尝试从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\u classpath添加到hadoop\u classpath中波斯特建议,但我得到同样的错误。。
2条答案
按热度按时间ymdaylpp1#
通过如下设置“hadoop\u classpath”并在同一终端中运行hadoop/hbase jar解决问题:
打开jar
hjqgdpho2#
日志提示您运行jar需要依赖其他jar。比如hbase-client.jar
mkdir喜欢libs,将依赖jar放入libs的dir中并使用以下命令:java-djava.ext.dirs=///lib-jar///you's jar
希望能对你有所帮助。