9

I am trying to run a project in intellij and every time I run a particular class, I get the below error message:

*Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/streaming/StreamingContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.streaming.StreamingContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)**
Surya
  • 91
  • 1
  • 3

2 Answers2

2

I was facing the same issue for so long, my code was raising the same error while executing the following line:

val ssc = new StreamingContext(sc, Seconds(10))

my POM.xml looked like this:

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

You see that additional line <scope>? Once I removed that line from my POM file, the code was back on track, successfully executed.

So please make sure you remove the <scope> from the dependency.

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-streaming_2.11</artifactId>
        <version>2.3.4</version>
    </dependency>
Sankar
  • 546
  • 4
  • 15
-1

You have to add the spark-streaming dependency into SBT using the spark version :

libraryDependencies += "org.apache.spark" %% "spark-streaming" % "your spark version"

hawk
  • 1