Cannot resolve symbol hbase

RBB

I am new to HBase, I copied a sample java code from the internet, but I meet an error "Cannot resolve symbol hbase" when building this sample. I use Gradle to build this sample project and Intellij as IDE. The HBase server is a remoter server and I try to write a put sample at my windows laptop to test the HBase, but I am not familiar with HBase and Gradle, could someone suggest what I have missed? Here is my code

    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();
            }
        }

    }

Here is my 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'
}

errors shown in IDE

Stephen C

According to a JAR finder site, the org.apache.hadoop.hbase.TableName class is in the hbase-common JAR file.

That means that the dependency that you have in your build.gradle file should work. However, I don't think that the version number is correct. The most recent 2.x version in Maven Central is 2.2.2. (And 3.0.0-SNAPSHOT is not there ... naturally ... because Maven Central doesn't host SNAPSHOT artifacts!)

However, I recommend that you do what the HBase Documentation says (here):

"For Java applications using Maven, including the hbase-shaded-client module is the recommended dependency when connecting to a cluster."

The corresponding Gradle dependency is:

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

I am not familiar with Gradle, but I expect that there was another error message saying that it couldn't resolve the dependency for hbase-common version 2.7.3.

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

TOP lista

quentelabel

Arquivo