【问题标题】:Scala -- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/streaming/StreamingContextScala——线程“主”java.lang.NoClassDefFoundError中的异常:org/apache/spark/streaming/StreamingContext
【发布时间】:2018-04-21 06:32:28
【问题描述】:

我遇到错误

线程“主”java.lang.NoClassDefFoundError 中的异常

这是我的完整程序:

object StatefulNetworkWordCount {
  def updateFunction(newValues: Seq[Int], runningCount: Option[Int]): Option[Int] = {
    val newCount = runningCount.getOrElse(0) + newValues.sum
    Some(newCount)
  }

    // Set checkpoint directory
    ssc.checkpoint("E:\\sparkdata")

    // Create a DStream that will connect to hostname:port, like localhost:9999
    val lines = ssc.socketTextStream("localhost", 9999)

    // Split each line into words
    val words = lines.flatMap(_.split(" "))

    // Count each word in each batch
    val pairs = words.map(word => (word, 1))

    // Update state using `updateStateByKey`
    val runningCounts = pairs.updateStateByKey[Int](updateFunction _)

    // Print the first ten elements of each RDD generated in this DStream to the console
    runningCounts.print()

    ssc.start() // Start the computation
    ssc.awaitTermination() // Wait for the computation to terminate

还有我的 pom.xml 文件:///

<dependencies>

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.11</artifactId>
        <version>2.1.1</version>
    </dependency>

    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.8</version>
    </dependency>

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-streaming-kafka_2.11</artifactId>
        <version>1.6.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-sql_2.11</artifactId>
        <version>1.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-hive_2.11</artifactId>
        <version>1.6.0</version>
    </dependency>

    <dependency>
        <groupId>com.databricks</groupId>
        <artifactId>spark-csv_2.11</artifactId>
        <version>1.2.0</version>
    </dependency>




    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-streaming_2.11</artifactId>
        <version>2.1.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-streaming-twitter_2.11</artifactId>
        <version>1.6.0</version>
    </dependency>

    <dependency>
        <groupId>org.twitter4j</groupId>
        <artifactId>twitter4j-stream</artifactId>
        <version>3.0.3</version>
    </dependency>

    <!-- JDBC Connector Jar    -->

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.31</version>
    </dependency>
    <dependency>
        <groupId>au.com.bytecode</groupId>
        <artifactId>opencsv</artifactId>
        <version>2.4</version>
    </dependency>

</dependencies>
</project>

【问题讨论】:

  • 如果您提供完整的堆栈跟踪,会更容易跟踪。

标签: scala maven sbt


【解决方案1】:

您包含了不同版本的 spark。
你有 2.1.1 和 1.6.0 。

您应该为所有 spark 依赖项使用相同的 spark 版本

【讨论】:

  • 很高兴为您提供帮助。如果此答案解决了您的问题,请将其标记为已回答,以帮助未来的读者知道问题已解决。看这里:stackoverflow.com/help/someone-answers
猜你喜欢
  • 2018-08-11
  • 2021-07-22
  • 2017-03-24
  • 2017-01-30
  • 1970-01-01
  • 2022-01-07
  • 2018-08-09
  • 2017-11-22
  • 1970-01-01
相关资源
最近更新 更多