hbase java程序eclipse没有运行

时间:2017-08-22 13:19:16

标签: java hadoop mapreduce hbase

我的hbase java代码创建表

public class CreateTable { 

 public static void main( String args[] ) throws IOException {
 HBaseConfiguration hc = new HBaseConfiguration( new Configuration( ) );
 HTableDescriptor ht = new HTableDescriptor( "cdrs" );

 ht.addFamily( new HColumnDescriptor( "number:" ) );
 ht.addFamily( new HColumnDescriptor( "company:" ) );
 ht.addFamily( new HColumnDescriptor( "time:" ) ); 
 ht.addFamily( new HColumnDescriptor( "location:" ) );                                          
 HBaseAdmin hba = new HBaseAdmin( hc );
 System.out.println( "creating table..." );
 hba.createTable( ht );
 System.out.println( "done!" );
 }

运行我得到的代码的jar: -   hadoop jar hbase-0.0.1-SNAPSHOT.jar apache.hbase.CreateTable

 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop /hbase/HBaseConfiguration
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:227)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
 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)
    ... 4 more

我是hadoop和hbase的新手,并且在过去的几天里面临运行这个罐子的问题..非常感谢

2 个答案:

答案 0 :(得分:0)

你是否包含了hbase-common依赖? 如果您使用的是maven,那么当您包含hbase-client时,它将作为传递依赖项下载。

包:org.apache.hadoop.hbase

此外,新的HBaseConfiguration(... params ...)现已弃用,您应该使用HBaseConfiguration.create();

Configuration config = HBaseConfiguration.create();
config.setInt("timeout", timeout);
config.set("hbase.zookeeper.quorum",zkAddress);
config.set("hbase.zookeeper.property.clientPort", zkPort);
config.set("hbase.client.retries.number", nRetries);//check for configs applicable or use hbase-site and core-site configs
Connection connection = ConnectionFactory.createConnection(config);

答案 1 :(得分:0)

在新的hbase版本上制作fat jar有一个问题,jars被弃用了许多依赖项。所以我在外部eclipse中添加了hbase-client-1.2.6-jarhbase-common-1.2.6-jar。这解决了我的问题。