Java – How to include hbase-site .xml in the classpath

How to include hbase-site .xml in the classpath… here is a solution to the problem.

How to include hbase-site .xml in the classpath

I’m currently trying to get my HBase code to use the settings specified in my hbase-site.xml. It seems to use the default settings instead of those specified in the hbase-site.xml configuration file. I restarted the HBase cluster after updating the file, but it still doesn’t use my updated configuration file.

The cluster I use is 2 nodes, one of which is master. The configuration file on both nodes specifies the IP of the master node as zookeeper quorum. I think the problem is that the settings I specified in hbase-site.xml are not being used, because if I set zookeeper quorum to the same value as in my hbase-site.xml via code, the code works fine, but the second node cannot be a quorum if not specified by code, contact master.

config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", masterNodeIP);

I would really appreciate the instructions or links in the classpath on how to include hbase-site.xml into my code’s classpath. I developed with Eclipse on a Windows machine and installed the HBase environment on a Linux cluster. Because of dependencies, I usually use Eclipse to compile code.

Ideally, I would like each node in the cluster to use its own configuration file.

Thanks in advance!

Solution

If whatever you put in hbase-site.xml, it uses the default, which could mean that it is being overwritten by another file in the classpath. This is quite possible because there is already a conf-site .xml in the hbase jar.

To resolve this issue, edit your classpath to add a directory containing your hbase-site.xml at the end of the classpath to ensure that nothing overwrites it. Something like this:

java -cp $CLASSPATH:/usr/lib/hbase/conf path.to.your.Mainclass

If it gets too obscure, I recommend running it from the command line instead of in Eclipse so you can be completely sure what’s in the classpath.

Hope this helps.

Related Problems and Solutions