简体   繁体   中英

Unable to Scan table in Hbase using Java Client API

I'm trying to scan a table in Hbase and retrieve all records in it. This is the method which I use to scan table. I build project using Maven.

 public void getAllRecord (String tableName) {
    try{
        HTable table = new HTable(configuration, tableName);
        Scan s = new Scan();
        ResultScanner ss = table.getScanner(s);
        for(Result r:ss){
            for(KeyValue kv : r.raw()){
                System.out.print(new String(kv.getRow()) + " ");
                System.out.print(new String(kv.getFamily()) + ":");
                System.out.print(new String(kv.getQualifier()) + " ");
                System.out.print(kv.getTimestamp() + " ");
                System.out.println(new String(kv.getValue()));

                break;
            }
        }
    } catch (IOException e){
        e.printStackTrace();
    }
}

These are my Maven dependancies

 <dependencies>
    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-thrift</artifactId>
        <version>0.98.2-hadoop2</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-client</artifactId>
        <version>0.96.0-hadoop2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-auth</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.opennlp</groupId>
        <artifactId>opennlp-tools</artifactId>
        <version>1.5.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.opennlp</groupId>
        <artifactId>opennlp-maxent</artifactId>
        <version>3.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.solr</groupId>
        <artifactId>solr-solrj</artifactId>
        <version>4.9.0</version>
    </dependency>

</dependencies>

But the problem is when I run this method I receive following error.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/util/SoftValueSortedMap

Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.util.SoftValueSortedMap

How can I solve this problem?

It seems like some jars are missing from your classpath. You either forgot to add util jar to classpath, or for some reason it was not included(could be that is was intentionally excluded with maven by tag)

Resolved the problem by adding following dependancy to project

    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-client</artifactId>
        <version>0.96.0-hadoop2</version>
    </dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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