【问题标题】:Configuration to run Hadoop with HBase使用 HBase 运行 Hadoop 的配置
【发布时间】:2016-05-26 09:40:14
【问题描述】:

我正在尝试使用 scala 代码探索 HBase API 所以我想根据here - Official Scala documentation 的引用设置一个简单的独立 scala 项目(使用 SBT)。这是我的 build.sbt

name := "hbase-sandbox"

version := "1.0"

scalaVersion := "2.10.4"

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" % "*" % "2.7.1",
  "org.apache.hbase" % "hbase-client" % "1.1.2"
)

这是文档中提到的代码

import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{Connection,ConnectionFactory,HBaseAdmin,HTable,Put,Get}
import org.apache.hadoop.hbase.util.Bytes

object Main extends App {
  val conf = new HBaseConfiguration()
  val connection = ConnectionFactory.createConnection(conf)
  val admin = connection.getAdmin()

  // list the tables
  val listtables=admin.listTables()
  listtables.foreach(println)

  // let's insert some data in 'mytable' and get the row

  val table = new HTable(conf, "mytable")

  val theput= new Put(Bytes.toBytes("rowkey1"))

  theput.add(Bytes.toBytes("ids"),Bytes.toBytes("id1"),Bytes.toBytes("one"))
  table.put(theput)

  val theget= new Get(Bytes.toBytes("rowkey1"))
  val result=table.get(theget)
  val value=result.value()
  println(Bytes.toString(value))
}

错误/异常

Error:(1, 8) object HBaseConfiguration is not a member of package org.apache.hadoop.hbase
import org.apache.hadoop.hbase.HBaseConfiguration
       ^
Error:(3, 8) object Bytes is not a member of package org.apache.hadoop.hbase.util
import org.apache.hadoop.hbase.util.Bytes
       ^
Error:(6, 18) not found: type HBaseConfiguration
  val conf = new HBaseConfiguration()
                 ^

我无法使用 hbase 下载 hadoop。 sbt 无法解决依赖关系。我已经尝试了 Hadoop 和 Hbase 版本的各种组合。而且org.apache.hbase#hbase~1.1.2jars在apache repository中不存在

如果我没有走上正确的道路,那么设置一个简单的 SBT 项目以在 scala 中试验 HBase API 的正确方法应该是什么。

更新

具有相同依赖版本的相同代码与 Maven 项目一样工作所以我猜问题出在一些 SBT 依赖解析器或类似的东西上。

【问题讨论】:

    标签: apache scala hadoop sbt hbase


    【解决方案1】:

    在您链接到的文档中,Ivy 依赖项看起来与您的代码中的不同。这是来自文档:

    libraryDependencies ++= Seq(
      "org.apache.hadoop" % "hadoop-core" % "0.20.2",
      "org.apache.hbase" % "hbase" % "0.90.4"
    )
    

    这是你的:

    libraryDependencies ++= Seq(
      "org.apache.hadoop" % "*" % "2.7.1",
      "org.apache.hbase" % "hbase-client" % "1.1.2"
    )
    

    除了不同的修订号之外,工件名称中的通配符也是问题所在。 SBT 不支持这个。

    【讨论】:

      猜你喜欢
      • 2013-03-22
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      相关资源
      最近更新 更多