Creating Hbase Table using Java


I am trying to create Hbase table using Java source code.
This is my source code

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.conf.Configuration;

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

      Configuration con = HBaseConfiguration.create();

      HBaseAdmin admin = new HBaseAdmin(con);

      HTableDescriptor tableDescriptor = new

      tableDescriptor.addFamily(new HColumnDescriptor("personal"));
      tableDescriptor.addFamily(new HColumnDescriptor("professional"));

      System.out.println(" Table created ");

I compiled the program using these commands on the command line
javac -Xlint:overrides -cp "/usr/hdp/current/hadoop-client/*:/usr/hdp/current/hbase-client/lib/*"

Then I made the program run by using the command:
java -cp ".:/usr/hdp/current/hadoop-client/*:/usr/hdp/current/hbase-client/lib/*" hbaseRelated

I am not able to create the table using this method in HBase
The errors are
Exception in thread “main” org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=35, exceptions:

Caused by: org.apache.hadoop.hbase.MasterNotRunningException: Can’t get master address from ZooKeeper; znode data == null

Caused by: Can’t get master address from ZooKeeper; znode data == null


Sample for creating database on HBase using Java
Sample for creating database on HBase using Java
Sample for creating database on HBase using Java

While experimenting I put the following values at appropriate place
Configuration conf = HBaseConfiguration.create();

I place the required xml files at the path that has been mentioned but got some different kind
of errors.


Are you still facing this issue?


Yes I am stuck
. Is it possible for you to help me on this. I have posted this on many places on this forum but of no avail.



Can you please refer below:



I am facing the same issue. I created a JAR file to read and write to HBase table.

But receiving this exception:
Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/MasterNotRunningException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at org.apache.hadoop.util.RunJar.main(
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.MasterNotRunningException
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(

The command i am using is:
HADOOP_CLASSPATH=‘hbase classpath’ hadoop jar HBase_Customize.jar H

I tried running this command to start the HBase master service but didnt work:
sudo service hbase-master start

Can you please advise the fix for this?


I think it should be:
HADOOP_CLASSPATH=`hbase classpath`

Did you notice the difference? It is backquote not single quote.