【问题标题】:HBase with Scala class Connection* cannot be imported无法导入具有 Scala 类 Connection* 的 HBase
【发布时间】:2017-10-11 20:44:04
【问题描述】:

我正在尝试从 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

任何想法我缺少什么或这段代码有什么问题?

【问题讨论】:

    标签: scala hadoop sbt hbase


    【解决方案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
    

    【讨论】:

    • 如果你喜欢,别忘了投票:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多