(Updated) Java Example Code using HBase Data Model Operations

This is the updated version to previous post on 2012: Java Example Code using HBase Data Model Operations

This time we will use latest stable Hbase (1.2.5), IntelliJ and Maven.

  • My local test environment: Virtual Box of Ubuntu 16 Desktop version.
  • Install HBase: https://hbase.apache.org/book.html#quickstart
    • Note: I use stable version 1.2.5 instead of 2.0.0
    • Open a terminal
      1. start HBase in terminal: bin/start-hbase.sh
      2. start HBase shell: bin/hbase shell
      3. create a table: create ‘myLittleHBaseTable’, ‘myLittleFamily’
  • To install JDK: sudo apt install openjdk-8-jre-headless
  • To install Maven: sudo apt install maven
  • Create a maven project (replace “autofei” to whatever you like): mvn archetype:generate -DgroupId=autofei -DartifactId=autofei -DarchetypeArtifactId=maven-archetype-quickstart
  • Download IntelliJ community version

Open the project in IntelliJ and add following dependencies to the pom.xml:

<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-common</artifactId>
  <version>2.7.3</version>
</dependency>
<dependency>
  <groupId>org.apache.hbase</groupId>
  <artifactId>hbase</artifactId>
  <version>1.2.5</version>
</dependency>
<dependency>
  <groupId>org.apache.hbase</groupId>
  <artifactId>hbase-client</artifactId>
  <version>1.2.5</version>
</dependency>

Enable auto-import function for IntelliJ to easy your life 🙂

The example code in the old post will still work but with some deprecation warning.