How to Execute jave code for HBASE in CLOUDXLab

Hi,

I have written a java code to create a TABLE in hbase.I have exported code from my eclipse to HDFS using hue. learnhbase.jar.Now I want to execute this code.
Could you please let me know how to execute it.

I have tried HADOOP JAR learnhbase.jar learnhbase.createtable but I have got class not found exception.

package learnhbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;

public class CreateTable {

public static void main (String[] args) throws IOException{
//get configuration
Configuration conf = HBaseConfiguration.create();
// Instantiating hbase admin class
//HBaseAdmin admin = new HBaseAdmin(conf);
//Instantiating table descriptor class
HTable hTable = new HTable(conf, “CHARAN”);
System.out.println("Table is: " + Bytes.toString(hTable.getTableName()));
hTable.close();

}
}

1 Like

HI Charan,

You have will have to first set the hadoop class path and then run it with hadoop jar in the following way:

export HBASE_HOME=/usr/hdp/current/hbase-client/
export HADOOP_CLASSPATH="$HADOOP_CLASSPATH:$HBASE_HOME/lib/*"
hadoop jar learnhbase.jar  learnhbase.CreateTable

I was able to run the program you have written. The following screenshot is the result:

Also, please not that you can also write the hbase map-reduce code in the similar fashion. You will have to initialize the job inside the main method. In the following way:

TableMapReduceUtil.initTableMapperJob(“test”,scan, TestMapper.class, Text.class, IntWritable.class, job);