Makefile for HBase Applications

hbase-makefile-225x225In my blog Makefile for Hadoop WordCount Example I presented a generic Makefile that could be adapted to build any Hadoop application, including WordCount.

Lately I’ve been exploring HBase programming and find myself in need of a similar device for building HBase applications. In this article I’ll show you how to modify the Hadoop Makefile for HBase. 

The key difference in this new Makefile is the addition of the HBase classpath which we can get from the hbase command just like we can with the hadoop command. In this example we just concatenate the two classpaths.

HADOOP = <path to Hadoop>
HBASE = <path to HBase>

APP = <application>
SRC = src/*.java 
OUT = out

$(APP): $(SRC) 
        mkdir -p $(OUT) 
        javac -classpath `$(HADOOP) classpath`:`$(HBASE) classpath` -d $(OUT) $(SRC) 
        jar -cvf $(APP).jar -C $(OUT) .

        rm -rf $(OUT) *.jar

To adapt this Makefile to other applications, follow these instructions:

  1. Create a directory for your application.
  2. cd to this directory and create a directory src.
  3. Place your java source code into src.
  4. Set HADOOP to point to your Hadoop binary.
  5. Set HBASE to point to your HBase binary.
  6. Set APP to the name of your application.
  7. Set SRC to the list of source files for your project.
  8. Set OUT to the directory where the compiled class files will be placed.
  9. Type make to build your app.
  10. Run your app by typing:
java -cp `hbase classpath`:`hadoop classpath`:<app jar>.jar <package>.<class>

You can download a copy of this Makefile by right clicking and saving this link to your system.  Get the Makefile from this link instead of copying and pasting the previous text because the file from the link has the right tab spaces that the make program insists upon.


Article by Vic Hargrave

Software developer, blogger and family man enjoying life one cup of coffee at a time. I like programming and writing articles on tech topics. And yeah, I like coffee.

Leave a Reply

Your email address will not be published. Required fields are marked *