windows上java api 连接Hbase失败,但是Linux系统上同样操作成功

kouwenxuan 2014-12-01 05:40:37
创建一个简单的表

package org.mstc.hbase.util;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
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.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.junit.Test;

public class Demo01 {

@Test
public void test01() {
Configuration conf = HBaseConfiguration.create();
conf.addResource("hbase-site.xml");
// conf.set("hbase.rootdir", "192.168.163.131:9000/hbase");
// conf.set("hbase.zookeeper.quorum", "192.168.163.131");
// conf.set("hbase.zookeeper.property.clientPort", "2181");
// conf.set("hbase.master", "192.168.163.131:60000");
HBaseAdmin admin;
try {
admin = new HBaseAdmin(conf);
HTableDescriptor table = new HTableDescriptor(TableName.valueOf("testTable"));
table.addFamily(new HColumnDescriptor("f1"));
table.addFamily(new HColumnDescriptor("f2"));
admin.createTable(table);
System.out.println(conf.get("hbase.master"));
} catch (MasterNotRunningException e) {
System.out.println("master not running");
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
System.out.println("zookeeper not connection");
e.printStackTrace();
} catch (IOException e) {
System.out.println("io exception");
e.printStackTrace();
}
}
}


src下的hbase-site.xml文件

<configuration>

<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.163.131:9000/hbase</value>
</property>

<property>
<name>hbase.tmp.dir</name>
<value>file:/usr/local/hbase/tmp</value>
</property>

<property>
<name>hbase.master</name>
<value>hdfs://192.168.163.131:60000</value>
</property>

<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>file:/usr/local/zookeeper/data</value>
</property>

<property>
<name>hbase.zookeeper.property.dataLogDir</name>
<value>file:/usr/local/zookeeper/logs</value>
</property>

<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>

<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>

<property> 
<name>hbase.zookeeper.quorum</name> 
<value>192.168.163.131</value>
</property>

</configuration>

报错信息
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2014-12-01 17:27:09,324 INFO zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(121)) - Process identifier=hconnection-0x25057fe connecting to ZooKeeper ensemble=192.168.163.131:2181
io exception
java.io.IOException: java.lang.reflect.InvocationTargetException
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:411)
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:388)
at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:269)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:192)
at org.mstc.hbase.util.Demo01.test01(Demo01.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:409)
... 27 more
Caused by: java.lang.ExceptionInInitializerError
at org.apache.hadoop.hbase.ClusterId.parseFrom(ClusterId.java:64)
at org.apache.hadoop.hbase.zookeeper.ZKClusterId.readClusterIdZNode(ZKClusterId.java:69)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getClusterId(ZooKeeperRegistry.java:83)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.retrieveClusterId(HConnectionManager.java:837)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.<init>(HConnectionManager.java:640)
... 32 more
Caused by: java.lang.RuntimeException: Failed to create local dir file:\usr\local\hbase\tmp\local\jars, DynamicClassLoader failed to init
at org.apache.hadoop.hbase.util.DynamicClassLoader.<init>(DynamicClassLoader.java:94)
at org.apache.hadoop.hbase.protobuf.ProtobufUtil.<clinit>(ProtobufUtil.java:201)
... 37 more

以上错误只有在windows上才会有,我换Linux操作系统就没有问题。搞不懂问题出在哪里
...全文
1555 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
kouwenxuan 2014-12-02
  • 打赏
  • 举报
回复
引用 9 楼 wulinshishen 的回复:
你把hbase-site.xml 里面 hbase.tmp.dir 这个属性去掉试试。
成功了,非常感谢,果然大神,阿里嘎多
  • 打赏
  • 举报
回复
你把hbase-site.xml 里面 hbase.tmp.dir 这个属性去掉试试。
kouwenxuan 2014-12-02
  • 打赏
  • 举报
回复
引用 7 楼 wulinshishen 的回复:
控制台的报错信息是什么呢?

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2014-12-01 17:27:09,324 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(121)) - Process identifier=hconnection-0x25057fe connecting to ZooKeeper ensemble=192.168.163.131:2181
io exception
java.io.IOException: java.lang.reflect.InvocationTargetException
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:411)
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:388)
at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:269)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:192)
at org.mstc.hbase.util.Demo01.test01(Demo01.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:409)
... 27 more
Caused by: java.lang.ExceptionInInitializerError
at org.apache.hadoop.hbase.ClusterId.parseFrom(ClusterId.java:64)
at org.apache.hadoop.hbase.zookeeper.ZKClusterId.readClusterIdZNode(ZKClusterId.java:69)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getClusterId(ZooKeeperRegistry.java:83)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.retrieveClusterId(HConnectionManager.java:837)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.<init>(HConnectionManager.java:640)
... 32 more
Caused by: java.lang.RuntimeException: Failed to create local dir file:\usr\local\hbase\tmp\local\jars, DynamicClassLoader failed to init
at org.apache.hadoop.hbase.util.DynamicClassLoader.<init>(DynamicClassLoader.java:94)
at org.apache.hadoop.hbase.protobuf.ProtobufUtil.<clinit>(ProtobufUtil.java:201)
... 37 more
  • 打赏
  • 举报
回复
控制台的报错信息是什么呢?
kouwenxuan 2014-12-02
  • 打赏
  • 举报
回复
引用 5 楼 wulinshishen 的回复:
DynamicClassLoader 源码中 String localDirPath = conf.get(LOCAL_DIR_KEY, DEFAULT_LOCAL_DIR) + DYNAMIC_JARS_DIR; localDir = new File(localDirPath); if (!localDir.mkdirs() && !localDir.isDirectory()) { throw new RuntimeException("Failed to create local dir " + localDir.getPath() + ", DynamicClassLoader failed to init"); } protected static final String LOCAL_DIR_KEY = "hbase.local.dir"; hbase.local.dir:作为本地存储,位于本地文件系统的路径。默认: ${hbase.tmp.dir}/local/ 需要从这个指定路径下的jar files 加载类,Windows下没有这个路径,因此不能加载类
既然是windows下没有这个路径,那大家都怎么从windows连接Hbase呢?,之前按你所说configuration.set()了一些属性,没作用呢,求大神不吝赐教
  • 打赏
  • 举报
回复
DynamicClassLoader 源码中 String localDirPath = conf.get(LOCAL_DIR_KEY, DEFAULT_LOCAL_DIR) + DYNAMIC_JARS_DIR; localDir = new File(localDirPath); if (!localDir.mkdirs() && !localDir.isDirectory()) { throw new RuntimeException("Failed to create local dir " + localDir.getPath() + ", DynamicClassLoader failed to init"); } protected static final String LOCAL_DIR_KEY = "hbase.local.dir"; hbase.local.dir:作为本地存储,位于本地文件系统的路径。默认: ${hbase.tmp.dir}/local/ 需要从这个指定路径下的jar files 加载类,Windows下没有这个路径,因此不能加载类
kouwenxuan 2014-12-02
  • 打赏
  • 举报
回复
引用 1 楼 hqshaozhu 的回复:
Caused by: java.lang.RuntimeException: Failed to create local dir file:\usr\local\hbase\tmp\local\jars, DynamicClassLoader failed to init。 这个路径很显然是hbase下的吧
请问一下,这个路径问题怎么产生的,为啥Linux上运行代码就没有问题呢
kouwenxuan 2014-12-02
  • 打赏
  • 举报
回复
引用 2 楼 wulinshishen 的回复:
Caused by: java.lang.RuntimeException: Failed to create local dir file:\usr\local\hbase\tmp\local\jars, DynamicClassLoader failed to init 提示是目录路径问题,Windows环境下直接往configuration 里面set 一些必要属性就可以了 Configuration configuration = new Configuration(); /** 与hbase/conf/hbase-site.xml中hbase.master配置的值相同 */ configuration.set("hbase.master", "192.168.10.20:60000"); /** 与hbase/conf/hbase-site.xml中hbase.zookeeper.quorum配置的值相同 */ configuration.set("hbase.zookeeper.quorum", "192.168.10.20"); /** 与hbase/conf/hbase-site.xml中hbase.zookeeper.property.clientPort配置的值相同 */ configuration.set("hbase.zookeeper.property.clientPort", "2181");
我直接conf.addResource("hbase-site.xml");不是一样的效果么,
  • 打赏
  • 举报
回复
Caused by: java.lang.RuntimeException: Failed to create local dir file:\usr\local\hbase\tmp\local\jars, DynamicClassLoader failed to init 提示是目录路径问题,Windows环境下直接往configuration 里面set 一些必要属性就可以了 Configuration configuration = new Configuration(); /** 与hbase/conf/hbase-site.xml中hbase.master配置的值相同 */ configuration.set("hbase.master", "192.168.10.20:60000"); /** 与hbase/conf/hbase-site.xml中hbase.zookeeper.quorum配置的值相同 */ configuration.set("hbase.zookeeper.quorum", "192.168.10.20"); /** 与hbase/conf/hbase-site.xml中hbase.zookeeper.property.clientPort配置的值相同 */ configuration.set("hbase.zookeeper.property.clientPort", "2181");
少主无翼 2014-12-01
  • 打赏
  • 举报
回复
Caused by: java.lang.RuntimeException: Failed to create local dir file:\usr\local\hbase\tmp\local\jars, DynamicClassLoader failed to init。 这个路径很显然是hbase下的吧

20,808

社区成员

发帖
与我相关
我的任务
社区描述
Hadoop生态大数据交流社区,致力于有Hadoop,hive,Spark,Hbase,Flink,ClickHouse,Kafka,数据仓库,大数据集群运维技术分享和交流等。致力于收集优质的博客
社区管理员
  • 分布式计算/Hadoop社区
  • 涤生大数据
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧