In 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) . clean: rm -rf $(OUT) *.jar
To adapt this Makefile to other applications, follow these instructions:
- Create a directory for your application.
- cd to this directory and create a directory src.
- Place your java source code into src.
- Set HADOOP to point to your Hadoop binary.
- Set HBASE to point to your HBase binary.
- Set APP to the name of your application.
- Set SRC to the list of source files for your project.
- Set OUT to the directory where the compiled class files will be placed.
- Type make to build your app.
- 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.
Author: Vic Hargrave