KafkaUtils class not found in Spark streaming

后端 未结 9 1555
囚心锁ツ
囚心锁ツ 2021-01-11 20:14

I have just began with Spark Streaming and I am trying to build a sample application that counts words from a Kafka stream. Although it compiles with sbt package

9条回答
  •  悲哀的现实
    2021-01-11 20:36

    import org.apache.spark.streaming.kafka.KafkaUtils
    

    use the below in build.sbt


    name := "kafka"
    
    version := "0.1"
    
    scalaVersion := "2.11.12"
    
    retrieveManaged := true
    
    fork := true
    
    //libraryDependencies += "org.apache.spark" % "spark-streaming_2.11" % "2.2.0"
    //libraryDependencies += "org.apache.spark" % "spark-streaming-kafka-0-8_2.11" % "2.1.0"
    
    libraryDependencies += "org.apache.spark" %% "spark-core" % "2.2.0"
    
    //libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.2.0"
    
    libraryDependencies += "org.apache.spark" %% "spark-streaming" % "2.2.0"
    
    // https://mvnrepository.com/artifact/org.apache.spark/spark-streaming-kafka-0-8
    libraryDependencies += "org.apache.spark" %% "spark-streaming-kafka-0-8" % "2.2.0" % "provided"
    
    // https://mvnrepository.com/artifact/org.apache.spark/spark-streaming-kafka-0-8-assembly
    libraryDependencies += "org.apache.spark" %% "spark-streaming-kafka-0-8-assembly" % "2.2.0"
    

    This will fix the issue

提交回复
热议问题