Error while connecting hbase with java

228 views
Skip to first unread message

Prabakaran K

unread,
Jan 28, 2015, 1:40:39 PM1/28/15
to chenn...@googlegroups.com
Hi

I am getting following error while connect hbase with javacode
I got this code from site

package mySQL;

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTablePool;


public class HbaseClient {

/**
* @param args
* @throws IOException 
* @throws MasterNotRunningException 
*/
public static void main(String[] args) throws MasterNotRunningException, IOException {
HBaseConfiguration conf=new HBaseConfiguration();
 conf.set("hbase.master","localhost");
 HTablePool pool=new HTablePool(conf,10);
/* _hUtil=new HUtil();
 _hUtil.setPool(pool);*/
 HBaseAdmin admin=new HBaseAdmin(conf);
 try {
   admin.disableTable("test_simple-by_photoId");
   admin.deleteTable("test_simple-by_photoId");
 }
catch (  TableNotFoundException e) {
 }
 try {
   admin.disableTable("test_simple");
   admin.deleteTable("test_simple");
 }
catch (  TableNotFoundException e) {
 }
 HTableDescriptor by_photoId_idx=new HTableDescriptor("test_simple-by_photoId");
 by_photoId_idx.addFamily(new HColumnDescriptor("__idx__"));
 by_photoId_idx.addFamily(new HColumnDescriptor("props"));
 admin.createTable(by_photoId_idx);
 HTableDescriptor test_simple=new HTableDescriptor("test_simple");
 test_simple.addFamily(new HColumnDescriptor("props"));
 admin.createTable(test_simple);  System.out.println("Done......");
}

}





Error:

log4j:WARN No appenders could be found for logger (org.apache.hadoop.hbase.HBaseConfiguration).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/zookeeper/KeeperException
at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:157)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:90)
at mySQL.HbaseClient.main(HbaseClient.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.zookeeper.KeeperException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 3 more

Prabakaran K

unread,
Jan 28, 2015, 2:15:33 PM1/28/15
to chenn...@googlegroups.com
Add zookeeper.jar but now getting below error

log4j:WARN No appenders could be found for logger (org.apache.hadoop.hbase.HBaseConfiguration).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
at org.apache.hadoop.hbase.zookeeper.ZKUtil.logRetrievedMsg(ZKUtil.java:1109)
at org.apache.hadoop.hbase.zookeeper.ZKUtil.getDataAndWatch(ZKUtil.java:550)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker.start(ZooKeeperNodeTracker.java:73)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.setupZookeeperTrackers(HConnectionManager.java:306)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.<init>(HConnectionManager.java:295)
at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:157)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:90)
at mySQL.HbaseClient.main(HbaseClient.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 8 more


--
You received this message because you are subscribed to the Google Groups "Hadoop Users Group (HUG) Chennai" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chennaihug+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Senthil Kumar

unread,
Jan 28, 2015, 2:19:04 PM1/28/15
to chenn...@googlegroups.com
Hi Prabhakaran,

You are missing commons jar. My suggestion would be use maven based development or include most of the jars from <HBase>/lib folder.

Thanks
Senthil Kumar
To unsubscribe from this group and stop receiving emails from it, send an email to chennaihug+unsubscribe@googlegroups.com.

Prabakaran K

unread,
Jan 29, 2015, 2:12:39 AM1/29/15
to chenn...@googlegroups.com
Thanks Senthil...
To unsubscribe from this group and stop receiving emails from it, send an email to chennaihug+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages