s.s
s.s

Reputation: 93

error in running hbase java program

this is my java hbase createtable program below:-

 public class createtable 
 {

  public static void main(String[] args) throws IOException 

  {   
       Configuration conf = HBaseConfiguration.create();    
       conf.set("hbase.zookeeper.quorum", "sandbox.hortonworks.com");
       conf.set("hbase.zookeeper.property.clientPort", "2181");
       conf.set("zookeeper.znode.parent", "/hbase-unsecure");
       HBaseAdmin admin = new HBaseAdmin(conf);
       HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("people"));
       tableDescriptor.addFamily(new HColumnDescriptor("personal"));
       tableDescriptor.addFamily(new HColumnDescriptor("contactinfo"));
       admin.createTable(tableDescriptor);
       Put put = new Put(Bytes.toBytes("doe-john-m-12345");     
   }

after creating jar (table-0.0.1-SNAPSHOT.jar) of the program when i am running the command hadoop jar table-0.0.1-SNAPSHOT.jar table.createtable

i am getting

   Exception in thread "main" java.lang.NoClassDefFoundError:org/apachehadoop/hbase/HBaseConfiguration at 
    table.createtable.main(createtable.java:17)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav     a:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:234)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:148)                           Causedby:
     java.lang.ClassNotFoundException:org.apache.hadoop.hbase.HBase
     Configuration     
     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

 how do i resolve this error ??

Upvotes: 1

Views: 841

Answers (3)

s.s
s.s

Reputation: 93

i solved this issue as there is issue in making fat jar and the in new hbase version jars are deprecated with many dependency..so i also added hbase-client-1.2.6-jar and hbase-common-1.2.6-jar to eclipse externally and then building fat jar ...this solved my issue .

Upvotes: 0

Kamal
Kamal

Reputation: 9

Please read this blog: https://my-bigdata-blog.blogspot.com/2017/08/hbase-programming-on-map-reduce-with.html

Two points to make it work

1) You code should have TableMapReduceUtil.addDependencyJars(job);

2) On command line - before you execute the command do this:

export HADOOP_CLASSPATH=your-jar-path

export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:hbase classpath

This adds hbase libraries for execution. The one you add in maven/netbeans are for compilation.

Upvotes: 1

Satya
Satya

Reputation: 8881

Your code is not able to see hbase.jar . Try adding this piece in your pom.xml

<!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase -->
<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase</artifactId>
    <version>0.90.2</version>
</dependency>

And then run it .

Upvotes: 1

Related Questions