HBase and Eclispe IDE integration

In this post, we will be creating a sample HBase project in Eclipse IDE. It is required to have a local working instance of HBase (mine is 0.20.6 version) and Eclipse Helios version. I assume that you are aware of starting and stopping HBase.

Step 1 : Start HBase. Start Eclispe.Step 2 : Create a new Java Project (File -> New -> Java Project).
Step 3 : Fill up the form. (Here project name = Sample) and click next.

Step 4 : Select Libraries tag from it and click “Add External JARs”.

Step 5 : Browse to theĀ  $HBASE_HOME directory. ($HBASE_HOME is the directory where you have installed HBase).

Step 6 : Select hbase-0.20.6.jar and click Ok. Similarly add the (commons-logging-1.0.4.jar , log4j-1.2.15.jar, zookeeper-3.2.2.jar, hadoop-0.20.2-core.jar) present in $HBASE_HOME/lib folder and click Finish.Step 7: Create a class with main method and replace the contents with the code displayed below. The below code creates a sample table named Blogposts with 2 column family Author, Title

// HBaseTest.java
import java.io.IOException;

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;

public class HBaseTest {
public static void main(String[] args) {
// Try to create a Table with 2 column family (Title, Author)
HTableDescriptor descriptor = new HTableDescriptor(“blogposts”);
descriptor.addFamily(new HColumnDescriptor(“Title”));
descriptor.addFamily(new HColumnDescriptor(“Author”));

try {
// Create a HBaseAdmin
HBaseConfiguration config = new HBaseConfiguration();
HBaseAdmin admin = new HBaseAdmin(config);

// Create table
admin.createTable(descriptor);
System.out.println(“Table created…”);
} catch (IOException e) {
System.out.println(“IOError: cannot create Table.”);
e.printStackTrace();
}
}
}

Step 8 : Right click project in Package Explorer. Select Run as -> Java Application

Step 9: Check the output screen for any Exceptions, if not thats it.

Step 10: Confirm creation of the table using HBase Shell.

Thats it for now.. will create more posts on HBase soon :)

About these ads
This entry was posted in Cloud, Cluster, Hadoop, Technology. Bookmark the permalink.

2 Responses to HBase and Eclispe IDE integration

  1. James says:

    I set up an HBase cluster with one linux machine as master and 2 windows machines. I configured all 3 machines to work as regionservers. From the windows machine I did as explained above. When I clicked on “Run as Java Application”, I was asked to select a type from a list of items such as HMaster, HRegion, ZookeeperMain, etc. I selected ZookeeperMain and clicked on ok. It threw the following exception:

    java.net.ConnectException: Connection refused: no further information
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:574)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1119)
    11/04/18 13:54:47 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181
    11/04/18 13:54:48 WARN zookeeper.ClientCnxn: Session 0×0 for server null, unexpected error, closing socket connection and attempting reconnect

  2. fossman says:

    Greetings James,

    The class you selected, when you are prompted with a “Run as Java application” should be the name of the class you have written, I mean the class with the main method. For example, for the above Java program, you must execute the class HBaseTest.

    Thanks,
    Varadharajan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s