【问题标题】:spark streaming + kafka sbt compilationspark流+kafka sbt编译
【发布时间】:2016-12-30 14:59:05
【问题描述】:

我有一个火花流 + kafka 的例子。它在 IDE 中运行良好。但是当我尝试从控制台通过 SBT 编译它时,例如 sbt compile。出错了。

主类:

val conf = new SparkConf().setMaster("local[*]").setAppName("KafkaReceiver")
  val ssc = new StreamingContext(conf, Seconds(5))

  val kafkaStream1 = KafkaUtils.createStream(ssc, "localhost:2181", "spark-streaming-consumer-group", Map("t1" -> 5))
  //val kafkaStream2 = KafkaUtils.createStream(ssc, "localhost:2181", "spark-streaming-consumer-group", Map("topic2" -> 5))

  //kafkaStream.fla
  kafkaStream1.print()
  ssc.start()
  ssc.awaitTermination()

错误信息:

[error] bad symbolic reference. A signature in package.class refers to type compileTimeOnly
[error] in package scala.annotation which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling package.class.
Reference to method any2ArrowAssoc in object Predef should not have survived past type checking,
[error] it should have been processed and eliminated during expansion of an enclosing macro.
[error]   val kafkaStream1 = KafkaUtils.createStream(ssc, "localhost:2181", "spark-streaming-consumer-group", Map("t1" -> 5))
[error]                                                                                                           ^
[error] two errors found
[error] (compile:compileIncremental) Compilation failed

sbt:

    name := "test"
    val sparkVersion = "2.0.0"

    lazy val commonSettings = Seq(
      organization := "com.test",
      version := "1.0",
      scalaVersion := "2.11.8",
      test in assembly := {}
    )    
libraryDependencies ++= Seq(
  "org.apache.spark" % "spark-streaming_2.11" % sparkVersion,
  "org.apache.spark" % "spark-streaming-kafka-0-8_2.11" % sparkVersion
) 

您有解决方法的想法吗?

【问题讨论】:

标签: apache-spark apache-kafka sbt spark-streaming spark-streaming-kafka


【解决方案1】:

你能分享你的 build.sbt 吗?可能导致“错误符号引用”问题的原因之一是 scala 版本不匹配。请查看topic 了解有关该问题的更多详细信息。此外,请确保您使用的 Scala 版本与 spark 预期的版本相同,请查看this blog post 了解更多详细信息

【讨论】:

  • 我应该使用 scala 2.10 吗?
  • 这取决于您使用的 Spark 版本,例如 Spark 1.3.1 使用 Scala 2.10.4,但 Spark 2.0 使用 Scala 2.11.*,请查看您使用的 Spark 版本的文档使用
  • 真的很奇怪。我使用 spark 2.0.0 和 scala 2.11.8。更新的 build.sbt 使用了本手册 spark.apache.org/docs/latest/streaming-kafka-integration.html。在 IDE 中工作,但从命令行“sbt compile”有同样的错误...
猜你喜欢
  • 1970-01-01
  • 2016-01-13
  • 1970-01-01
  • 2020-01-07
  • 1970-01-01
  • 2017-04-07
  • 2016-03-12
  • 2014-12-01
  • 2017-07-22
相关资源
最近更新 更多