这是列出HBase表的代码....
package SunHbaseSample.HbaseApp;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class ListTables {
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
// Instantiating a configuration class
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class
HBaseAdmin admin = new HBaseAdmin(conf);
// Getting all the list of tables using HBaseAdmin object
HTableDescriptor[] tableDescriptor = admin.listTables();
// printing all the table names.
for (int i = 0; i < tableDescriptor.length; i++) {
System.out.println(tableDescriptor[i].getNameAsString());
}
}
}
我已经使用maven build创建了一个jar文件,并尝试运行它,如下所示。我正在收到错误,因为主人没有跑
[kumarsu@dhrslnl001 ~]$ hadoop jar HbaseApp-0.0.1-SNAPSHOT.jar SunHbaseSample.HbaseApp.ListTables
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/MasterNotRunningException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at org.apache.hadoop.util.RunJar.run(RunJar.java:215)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.MasterNotRunningException
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
答案 0 :(得分:0)
环境无法找到包含HBase
库类的jar。 org.apache.hadoop.hbase.MasterNotRunningException
是<HBASE_HOME>/lib/hbase-client.jar jar
的一部分,因此您需要在类路径中添加它,如下所示。
export HADOOP_CLASSPATH=<HBASE_HOME>/lib/hbase-client.jar
example.
export HADOOP_CLASSPATH=/usr/hdp/2.3.6.0-3796/hbase/lib/hbase-client.jar
导出HADDOP_CLASSPATH
后,hadoop命令会在类路径中添加$HADOOP_CLASSPATH
。