【问题标题】:Spark Streaming Context creation errorSpark Streaming 上下文创建错误
【发布时间】:2018-05-18 16:33:26
【问题描述】:

我正在尝试 Spark Streaming 基本编程。,

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

val appConf = new SparkConf().setMaster("local[2]").setAppName("kafkaapp");
val sContext = new StreamingContext(appConf , Seconds(1));

它返回以下内容

Caused by: java.lang.ClassNotFoundException: org.apache.spark.streaming.StreamingContext

我的配置

Spark Core 和 Streaming “2.1.1” 版本 Scala 版本 2.11.8

我做错了什么?

POM 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.demo</groupId>
  <artifactId>streamapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <inceptionYear>2008</inceptionYear>
  <properties>
    <scala.version>2.11.8</scala.version>
  </properties>

  <repositories>
    <repository>
      <id>scala-tools.org</id>
      <name>Scala-Tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>scala-tools.org</id>
      <name>Scala-Tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </pluginRepository>
  </pluginRepositories>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.11</artifactId>
      <version>2.1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming -->
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_2.11</artifactId>
      <version>2.1.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.specs</groupId>
      <artifactId>specs</artifactId>
      <version>1.2.5</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>

    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
          <args>
            <arg>-target:jvm-1.5</arg>
          </args>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>

【问题讨论】:

    标签: apache-spark spark-streaming


    【解决方案1】:

    检查您的运行时环境是否有带有 StreamingContext 的 JAR(应该是 spark-streaming_2.11.jar)。如果没有,请将缺少的依赖项添加到您的依赖项管理工具(Maven、SBT、Gradle...)中。

    【讨论】:

    • 我有 spark-streaming_2.11
    • 你能在第一个问题中添加你的 pom.xml 吗?这将有助于更好地理解问题。
    • 谢谢。由于您将这些依赖项标记为已提供,因此 Maven 不会从远程存储库中搜索它们。它希望您在本地主机上拥有它们。因此,您可以删除提供的标签并重试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-23
    • 2017-03-28
    • 2016-09-10
    • 2016-01-20
    • 1970-01-01
    • 2015-01-20
    相关资源
    最近更新 更多