从java连接到Hbase时出错

时间:2015-05-25 06:51:04

标签: apache hadoop mapreduce hbase

我使用HBase版本1.0.1,而我从java连接到hbase我得到错误

15/05/25 12:12:57 INFO zookeeper.ZooKeeper: Initiating client    connection,  connectString=localhost:2181 sessionTimeout=90000 watcher=hconnection-  0xc0663d0x0, quorum=localhost:2181, baseZNode=/hbase

Exception in thread "main" java.io.IOException: java.lang.reflect.InvocationTargetException
at   org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:240)
at org.apache.hadoop.hbase.client.ConnectionManager.createConnection(ConnectionManager.java:410)
at org.apache.hadoop.hbase.client.ConnectionManager.createConnection(ConnectionManager.java:403)
at org.apache.hadoop.hbase.client.ConnectionManager.getConnectionInternal(ConnectionManager.java:281)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:202)
at org.subhash.hbase.HBaseExample.main(HBaseExample.java:21)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:238)
... 5 more


Caused by: java.lang.NoClassDefFoundError: org/apache/htrace/Trace
at org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper.exists(RecoverableZooKeeper.java:218)
at org.apache.hadoop.hbase.zookeeper.ZKUtil.checkExists(ZKUtil.java:481)
at org.apache.hadoop.hbase.zookeeper.ZKClusterId.readClusterIdZNode(ZKClusterId.java:65)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getClusterId(ZooKeeperRegistry.java:86)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.retrieveClusterId(ConnectionManager.java:833)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.<init>(ConnectionManager.java:623)
... 10 more


Caused by: java.lang.ClassNotFoundException: org.apache.htrace.Trace
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more

我的Hadoop Deamons正在运行,hbase也在运行enter image description here

我的Java代码

 Configuration conf = HBaseConfiguration.create();


      @SuppressWarnings("deprecation")
      HBaseAdmin admin = new HBaseAdmin(conf);

      System.out.println("Conneccted" + conf.get("hbase.rootdir"));

请在这个问题上帮助我

提前致谢

1 个答案:

答案 0 :(得分:0)

看起来像jar(htrace-core.jar)包含问题。请将jar添加到项目类路径中以避免 &#34;引起:java.lang.ClassNotFoundException:org.apache.htrace.Trace&#34;