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

2

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

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 .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.