无法编译简单的 hbase java 程序

cannot compile a simple hbase java program

下面的程序是使用这个命令编译的:-

javac MyLittleHBaseClient.java -cp /usr/lib/hbase/hbase-client.jar:/usr/lib/hbase/hbase-common.jar:/etc/hbase/conf:/usr/lib/hadoop/hadoop-common.jar:/etc/hadoop/conf:/usr/lib/zookeeper/zookeeper.jar:/usr/lib/hadoop/lib/*.jar:/usr/lib/hadoop/lib/commons-configuration-1.6.jar:/usr/lib/hbase/hbase-server.jar:/usr/lib/hbase/hbase-hadoop-compat-0.98.6-cdh5.3.0.jar:/usr/lib/hbase/hbase-client-0.98.6-cdh5.3.0.jar     

代码:

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;

public class MyLittleHBaseClient {
  public static void main(String[] args) throws IOException {
    Configuration config = HBaseConfiguration.create();
    config.addResource("/etc/hbase/conf/hbase-site.xml");
    Connection connection = ConnectionFactory.createConnection(config);
    try {
      Table table = connection.getTable(TableName.valueOf("myTable"));
      try {
        Put p = new Put(Bytes.toBytes("myLittleRow"));
        p.add(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"),
        Bytes.toBytes("Some Value"));
        table.put(p);

        Get g = new Get(Bytes.toBytes("myLittleRow"));
        Result r = table.get(g);
        byte [] value = r.getValue(Bytes.toBytes("myLittleFamily"),
          Bytes.toBytes("someQualifier"));

        String valueStr = Bytes.toString(value);
        System.out.println("GET: " + valueStr);

        Scan s = new Scan();
        s.addColumn(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"));
        ResultScanner scanner = table.getScanner(s);
        try {
           for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
             System.out.println("Found row: " + rr);
           }

           // The other approach is to use a foreach loop. Scanners are iterable!
           // for (Result rr : scanner) {
           //   System.out.println("Found row: " + rr);
           // }
         } finally {
           scanner.close();
         }
       } finally {
         if (table != null) table.close();
       }
     } finally {
       connection.close();
     }
  }
}

这会导致以下错误。我不明白为什么在将 hbase-client jar 添加到类路径时出现以下错误。

 MyLittleHBaseClient.java:6: error: cannot find symbol
  import org.apache.hadoop.hbase.client.Connection;
                                       ^
    symbol:   class Connection
    location: package org.apache.hadoop.hbase.client
  MyLittleHBaseClient.java:7: error: cannot find symbol
  import org.apache.hadoop.hbase.client.ConnectionFactory;
                                       ^
    symbol:   class ConnectionFactory
    location: package org.apache.hadoop.hbase.client
  MyLittleHBaseClient.java:9: error: cannot find symbol
  import org.apache.hadoop.hbase.client.Table;
                                       ^
    symbol:   class Table
    location: package org.apache.hadoop.hbase.client
  MyLittleHBaseClient.java:25: error: cannot find symbol
      Configuration config = HBaseConfiguration.create();
      ^
    symbol:   class Configuration
    location: class MyLittleHBaseClient
  MyLittleHBaseClient.java:38: error: cannot find symbol
      Connection connection = ConnectionFactory.createConnection(config);
      ^
    symbol:   class Connection
    location: class MyLittleHBaseClient
  MyLittleHBaseClient.java:38: error: cannot find symbol
      Connection connection = ConnectionFactory.createConnection(config);
                              ^
    symbol:   variable ConnectionFactory
    location: class MyLittleHBaseClient
  MyLittleHBaseClient.java:46: error: cannot find symbol
        Table table = connection.getTable(TableName.valueOf("myTable"));
        ^
    symbol:   class Table
    location: class MyLittleHBaseClient
  7 errors

尝试以下操作。这应该涵盖 hbase 和 hadoop

下的所有 jar
javac -cp $(hbase classpath):$(hadoop classpath) MyLittleHBaseClient.java