繁体   English   中英

无法解析符号 hbase

[英]Cannot resolve symbol hbase

我是 HBase 的新手,我从互联网上复制了一个示例 java 代码,但是在构建此示例时遇到错误“无法解析符号 hbase” 我使用 Gradle 来构建这个示例项目,并使用 Intellij 作为 IDE。 HBase 服务器是一个远程服务器,我尝试在我的 Windows 笔记本电脑上编写一个放置示例来测试 HBase,但我不熟悉 HBase 和 Gradle,有人可以建议我错过了什么吗? 这是我的代码

    import java.io.IOException;

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.TableName;
    import org.apache.hadoop.hbase.client.Connection;
    import org.apache.hadoop.hbase.client.ConnectionFactory;
    import org.apache.hadoop.hbase.client.Put;
    import org.apache.hadoop.hbase.client.Table;
    import org.apache.hadoop.hbase.util.Bytes;

    public class PutHbaseClient {
        public static void main(String[] args) throws IOException {
            Configuration conf = HBaseConfiguration.create();

            Connection connection = ConnectionFactory.createConnection(conf);
            Table table = connection.getTable(TableName.valueOf("test"));
            try {
                /*
                 * Put operations for a single row. To perform a
                 * Put, instantiate a Put object with the row to insert to and for
                 * each column to be inserted, execute addcolumn.
                 */
                Put put1 = new Put(Bytes.toBytes("row1"));
                Put put2 = new Put(Bytes.toBytes("row2"));
                Put put3 = new Put(Bytes.toBytes("row3"));
                put1.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
                        Bytes.toBytes("ValueOneForPut1Qual1"));
                put2.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
                        Bytes.toBytes("ValueOneForPut2Qual1"));
                put3.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"),
                        Bytes.toBytes("ValueOneForPut2Qual1"));
                put1.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
                        Bytes.toBytes("ValueOneForPut1Qual2"));
                put2.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
                        Bytes.toBytes("ValueOneForPut2Qual2"));
                put3.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual2"),
                        Bytes.toBytes("ValueOneForPut3Qual3"));
                table.put(put1);
                table.put(put2);
                table.put(put3);
            } finally {
                table.close();
                connection.close();
            }
        }

    }

这是我的 build.gradle

 plugins {
    id 'java'
}

group 'gid'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()

}

dependencies {

    compile group: 'org.apache.hadoop', name: 'hadoop-common', version:'2.7.3'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

IDE 中显示的错误

我认为您的 gradle 依赖项中需要这样的东西:

compile 'org.apache.hbase:hbase:3.0.0-SNAPSHOT'

根据 JAR finder 站点, org.apache.hadoop.hbase.TableName类位于 hbase-common JAR 文件中。

这意味着您在 build.gradle 文件中的依赖项应该可以工作。 但是,我认为版本号不正确。 Maven Central 中的最新 2.x 版本是 2.2.2。 (并且 3.0.0-SNAPSHOT 不存在......自然......因为 Maven Central 不托管 SNAPSHOT 工件!)

但是,我建议您按照 HBase 文档中的说明进行操作(此处):

“对于使用 Maven 的 Java 应用程序,包括hbase-shaded-client模块是连接到集群时推荐的依赖项。”

对应的 Gradle 依赖是:

// https://mvnrepository.com/artifact/org.apache.hbase/hbase-shaded-client
compile group: 'org.apache.hbase', name: 'hbase-shaded-client', version: '2.2.2'

我对 Gradle 不熟悉,但我希望还有另一条错误消息说它无法解决 hbase-common 版本 2.7.3 的依赖关系。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM