使用hbase运行hadoop的配置

hc2pp10m  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(349)

我正在尝试用scala代码探索hbase API,所以我想设置一个简单的独立scala项目(使用sbt),下面是这里的参考资料—scala官方文档。这是我的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.2 apache存储库中不存在jar
如果我没有走上正确的道路,那么设置一个简单的sbt项目以在scala中试验hbase api的正确方法应该是什么呢。

更新

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

von4xj4u

von4xj4u1#

在您链接到的文档中,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不支持这个。

相关问题