尝试从Scala代码访问HBase时,我遇到了一个特殊的异常。
以下是该故事的长篇版本:
我在我的机器上以独立模式安装了HBase 1.2.6(Ubuntu 16.04)。 接下来,我尝试执行以下代码:
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.client.ConnectionFactory
import org.apache.hadoop.hbase.io.compress.Compression.Algorithm
import org.apache.hadoop.hbase.{HBaseConfiguration, HColumnDescriptor, HTableDescriptor, TableName}
object HelloWorld {
private val TABLE_NAME = "MY_TABLE_NAME_TOO"
private val CF_DEFAULT = "DEFAULT_COLUMN_FAMILY"
def main(args: Array[String]): Unit = {
val config: Configuration = HBaseConfiguration.create()
val connection = ConnectionFactory.createConnection(config)
val admin = connection.getAdmin
val table = new HTableDescriptor(TableName.valueOf(TABLE_NAME))
table.addFamily(new HColumnDescriptor(CF_DEFAULT).setCompressionType(Algorithm.NONE))
System.out.print("Creating table. ")
admin.createTable(table)
System.out.println(" Done.")
}
}
build.sbt
文件:
name := "myapp"
version := "1.0"
scalaVersion := "2.12.1"
libraryDependencies += "org.apache.storm" % "storm-core" % "1.0.3"
libraryDependencies += "org.apache.hbase" % "hbase-client" % "1.2.6" exclude("org.slf4j","slf4j-log4j12")
libraryDependencies += "org.apache.hbase" % "hbase-common" % "1.2.6" exclude("org.slf4j","slf4j-log4j12")
libraryDependencies += "org.apache.hadoop" % "hadoop-common" % "2.8.0" exclude("org.slf4j","slf4j-log4j12")
libraryDependencies += "org.apache.hbase" % "hbase-protocol" % "1.2.6" exclude("org.slf4j","slf4j-log4j12")
我使用以下命令从sbt执行代码:
$ sbt
> compile
> run
我收到以下错误:
[info] Running hbase.HelloWorld
[info] 566 [main] WARN o.a.h.u.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
[error] Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.security.authentication.util.KerberosUtil.hasKerberosTicket(Ljavax/security/auth/Subject;)Z
[error] at org.apache.hadoop.security.UserGroupInformation.<init>(UserGroupInformation.java:652)
[error] at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:843)
[error] at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:802)
[error] at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:675)
[error] at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:293)
[error] at org.apache.hadoop.hbase.security.User.getCurrent(User.java:191)
[error] at org.apache.hadoop.hbase.security.UserProvider.getCurrent(UserProvider.java:167)
[error] at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:215)
[error] at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119)
[error] at hbase.HelloWorld$.main(HelloWorld.scala:48)
[error] at hbase.HelloWorld.main(HelloWorld.scala)
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code returned from runner: 1
[error] Total time: 1 s, completed Jun 12, 2017 2:56:48 PM
行
时发生异常val connection = ConnectionFactory.createConnection(config)
已到达。
对我来说没有意义。我希望有人能够对这一点有所了解。
答案 0 :(得分:0)
删除此依赖项后,一切正常:
libraryDependencies += "org.apache.storm" % "storm-core" % "1.0.3"
显然一起使用Storm和HBase可能会有问题。 (我不知道如何解决这个问题。)