Support Questions

Find answers, ask questions, and share your expertise

Hbase Java API connection error

avatar
Rising Star

Hi,

I'm trying to connect from A java Application to Hbase like this:

Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum", "localhost");
        config.set("hbase.zookeeper.property.clientPort", "2181");
        config.set("zookeeper.znode.parent", "/hbase-unsecure");
        
        config.set("hbase.client.retries.number", Integer.toString(0));
        config.set("zookeeper.session.timeout", Integer.toString(60000));
        config.set("zookeeper.recovery.retry", Integer.toString(0));
        
        Connection conn = ConnectionFactory.createConnection(config);
        TableName TABLE_NAME = TableName.valueOf("weblog");
        Table table = conn.getTable(TABLE_NAME);
        Result r = table.get(new Get(Bytes.toBytes("row1")));
        System.out.println(r);

I builded the App into a JAR but when running it on the cluster with :

hadoop jar hbaseConnect-0.0.1-SNAPSHOT.jar com.packagename.hbaseConnect.HbaseConnect

i get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
    at com.DigiMerket.hbaseConnect.HbaseConnect.main(HbaseConnect.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

I tried to add HBASE_CLASSPATH to HADOOP_CLASSPATH in hadoop-env like this post suggests but I get the same error..

1 ACCEPTED SOLUTION

avatar

If you will run the following command (hadoop classpath) then you will be able to see that by default the HBase JARs will not be added to the "hadoop" command line utility.

# hadoop classpath

Also you can also try setting the "HADOOP_CLASSPATH" as following and then in the same terminal run your hadoop/hbase jar:

export HADOOP_CLASSPATH="$HADOOP_CLASSPATH:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-client.jar:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-common.jar:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-protocol-1.1.2.2.3.4.0-3485.jar:.:" 


hadoop  jar  hbaseConnect-0.0.1-SNAPSHOT.jar com.packagename.hbaseConnect.HbaseConnect

View solution in original post

3 REPLIES 3

avatar

If you will run the following command (hadoop classpath) then you will be able to see that by default the HBase JARs will not be added to the "hadoop" command line utility.

# hadoop classpath

Also you can also try setting the "HADOOP_CLASSPATH" as following and then in the same terminal run your hadoop/hbase jar:

export HADOOP_CLASSPATH="$HADOOP_CLASSPATH:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-client.jar:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-common.jar:/usr/hdp/2.3.4.0-3485/hbase/lib/hbase-protocol-1.1.2.2.3.4.0-3485.jar:.:" 


hadoop  jar  hbaseConnect-0.0.1-SNAPSHOT.jar com.packagename.hbaseConnect.HbaseConnect

avatar
Rising Star

Hi @Joy The solution you proposed worked, I'm getting a new error not related to a jar dependency. To make this fix permanent should I add that line to hadoop-env ?

avatar
New Contributor

hey,did you solved the issue ..i am getting the same error ..please help me with this

hadoop jar newtable-0.0.1-SNAPSHOT.jar newtable.createtable

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
at newtable.createtable.main(createtable.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:234)
at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)