我正在尝试从Hbase文档http://hbase.apache.org/1.2/book.html#scala编译并运行scala示例 但是我遇到了无法导入Connection和ConnectionFactory类的编译错误。
我尝试了两个scala版本2.10.6和2.11.11,但在两种情况下都失败了。
简单的Scala代码:
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.Connection
import org.apache.hadoop.hbase.client.ConnectionFactory
object Client {
def main(args: Array[String]): Unit = {
val conf = new HBaseConfiguration()
val connection = ConnectionFactory.createConnection(conf)
val admin = connection.getAdmin()
// list the tables
val listtables=admin.listTables()
listtables.foreach(println)
}
}
Sbt文件(sbt版本0.13.15):
name := "HBaseScalaClient"
scalaVersion := "2.10.6"
resolvers += "Apache HBase" at "https://repository.apache.org/content/repositories/releases"
resolvers += "Thrift" at "http://people.apache.org/~rawson/repo/"
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-core" % "0.20.2",
"org.apache.hbase" % "hbase" % "0.90.4"
)
编译错误:
[error] /home/user/HBaseScala/Client.scala:2: object Connection is not a member of package org.apache.hadoop.hbase.client
[error] import org.apache.hadoop.hbase.client.Connection
[error] ^
[error] /home/user/HBaseScala/Client.scala:3: object ConnectionFactory is not a member of package org.apache.hadoop.hbase.client
[error] import org.apache.hadoop.hbase.client.ConnectionFactory
[error] ^
[error] /home/user/HBaseScala/Client.scala:9: not found: value ConnectionFactory
[error] val connection = ConnectionFactory.createConnection(conf)
[error] ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 1 s, completed May 12, 2017 3:30:48 PM
我缺少什么想法或这段代码有什么问题?
答案 0 :(得分:1)
尝试使用此库依赖项:
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-core" % "1.2.1",
"org.apache.hbase" % "hbase" % "1.2.0",
"org.apache.hbase" % "hbase-client" % "1.2.0",
"org.apache.hbase" % "hbase-common" % "1.2.0",
"org.apache.hbase" % "hbase-server" % "1.2.0"
)
并添加此导入:
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{ConnectionFactory,HBaseAdmin,HTable,Put,Get}
import org.apache.hadoop.hbase.util.Bytes