0

My hbase java code to create table

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!" );
 }

running the jar of the code i am getting :- 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

i am new to hadoop and hbase and facing problem to run this jar from past several days ..any help would be appreciated

s.s
  • 93
  • 2
  • 14
  • Possible duplicate of [Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration](https://stackoverflow.com/questions/26364057/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-hadoop-hba) – Îsh Aug 22 '17 at 13:34
  • yes but getting same error... – s.s Aug 22 '17 at 14:04

2 Answers2

0

Have you included the hbase-common dependency? If you are using maven, it will get downloaded as a transitive dependency when you include hbase-client.

Package: org.apache.hadoop.hbase

Also, new HBaseConfiguration(...params...) is now deprecated and instead, you should use 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);
Parijat Purohit
  • 921
  • 6
  • 16
0

There is an issue making fat jar on the new hbase version, jars are deprecated with many dependency.So I added hbase-client-1.2.6-jar and hbase-common-1.2.6-jar to eclipse externally .This solved my issue .

4b0
  • 21,981
  • 30
  • 95
  • 142
s.s
  • 93
  • 2
  • 14