gpt4 book ai didi

java - 使用 Java 连接到远程 HBase 服务

转载 作者:可可西里 更新时间:2023-11-01 14:20:55 25 4
gpt4 key购买 nike

我有一个小示例代码,我在其中尝试建立与远程 HBase 实体的连接。该代码在未安装 HBase 的 Windows 机器上运行,我尝试连接到安装并运行它的远程 Ubuntu 服务器。下面片段中的 IP 当然只是一个占位符。

代码如下:

public static void main(String[] args) {

Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin = null;

String ip = "10.10.10.10";
String port = "2181";

conf.set("hbase.zookeeper.quorum", ip);
conf.set("hbase.zookeeper.property.clientPort", port);

try {
admin = new HBaseAdmin(conf);
boolean bool = admin.tableExists("sensor_data");
System.out.println("Table exists? " + bool);
} catch (IOException e) {
e.printStackTrace();
}
}

但出于某种原因我得到了这个错误:

org.apache.hadoop.hbase.DoNotRetryIOException: java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.hbase.zookeeper.MetaTableLocator
at org.apache.hadoop.hbase.client.RpcRetryingCaller.translateException(RpcRetryingCaller.java:229)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:202)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:320)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:295)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:160)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:155)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:811)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:602)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:366)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:303)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:313)
at com.twoBM.Tests.HBaseWriter.main(HBaseWriter.java:26)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.hbase.zookeeper.MetaTableLocator
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:596)
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:580)
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:559)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation(ZooKeeperRegistry.java:61)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta(ConnectionManager.java:1185)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1152)
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:300)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:153)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:61)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
... 15 more

我正在使用 Gradle 构建我的项目,目前我只使用以下两个依赖项:

compile 'org.apache.hive:hive-jdbc:2.1.0'
compile 'org.apache.hbase:hbase:1.1.6'

有人知道如何解决这个问题吗?我尝试用谷歌搜索这个问题,但没有找到任何提供实际解决方案的链接。

最好的问候

最佳答案

这绝对是Google Guava的依赖冲突。自 Guava v.17 以来,Stopwatch 类的默认构造函数变成了私有(private)的,并且在更早的时候被标记为弃用。

因此,要使 HBase Java 客户端正常工作,您需要 Guava v.16 或更早版本。检查您构建应用程序的方式 (Maven/Gradle/Classpath) 并找到使用 Guava v.17+ 的依赖项。之后,您可以解决冲突。

关于java - 使用 Java 连接到远程 HBase 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39725234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com