簡體   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