Spark + Kafka streaming NoClassDefFoundError kafka/serializer/StringDecoder












2















I'm trying to send message from my kafka producer and stream it in spark streaming. But I'm getting the following error when I run my application on spark submit.



Error



 Exception in thread "main" java.lang.NoClassDefFoundError: kafka/serializer/StringDecoder
at com.spark_stream.Main.main(Main.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:736)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: kafka.serializer.StringDecoder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 10 more


Application code is as follows:



Main.java



package com.spark_stream;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.streaming.Duration;
import org.apache.spark.streaming.api.java.JavaPairInputDStream;
import org.apache.spark.streaming.api.java.JavaStreamingContext;
import org.apache.spark.streaming.kafka.KafkaUtils;

import kafka.serializer.StringDecoder;

public class Main {

public static void main(String args) {
// TODO Auto-generated method stub

System.out.println( "spark started!" );

SparkConf conf = new SparkConf()
.setAppName("kafka-sandbox")
.setMaster("local[*]");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaStreamingContext ssc = new JavaStreamingContext(sc, new Duration(2000));


Map<String, String> kafkaParams = new HashMap<String, String>();
kafkaParams.put("metadata.broker.list", "localhost:9092");
Set<String> topics = Collections.singleton("speed");

JavaPairInputDStream<String, String> directKafkaStream = KafkaUtils.createDirectStream(ssc,
String.class, String.class, StringDecoder.class, StringDecoder.class, kafkaParams, topics);

directKafkaStream.foreachRDD(rdd -> {
System.out.println("--- New RDD with " + rdd.partitions().size()
+ " partitions and " + rdd.count() + " records");
rdd.foreach(record -> System.out.println(record._2));
});

System.out.println( "connection completed" );


ssc.start();

ssc.awaitTermination();

System.out.println( "spark ended!" );

}

}


Pom.xml



<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spark_stream</groupId>
<artifactId>com.spark_stream</artifactId>
<version>0.0.1-SNAPSHOT</version>


<dependencies>

<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.6.0</version>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.10</artifactId>
<version>1.6.0</version>
</dependency>

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


</dependencies>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>


Couldn't find a solution for this error. Any help would be appreciated.










share|improve this question





























    2















    I'm trying to send message from my kafka producer and stream it in spark streaming. But I'm getting the following error when I run my application on spark submit.



    Error



     Exception in thread "main" java.lang.NoClassDefFoundError: kafka/serializer/StringDecoder
    at com.spark_stream.Main.main(Main.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:736)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
    Caused by: java.lang.ClassNotFoundException: kafka.serializer.StringDecoder
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 10 more


    Application code is as follows:



    Main.java



    package com.spark_stream;

    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Set;

    import org.apache.spark.SparkConf;
    import org.apache.spark.api.java.JavaSparkContext;
    import org.apache.spark.streaming.Duration;
    import org.apache.spark.streaming.api.java.JavaPairInputDStream;
    import org.apache.spark.streaming.api.java.JavaStreamingContext;
    import org.apache.spark.streaming.kafka.KafkaUtils;

    import kafka.serializer.StringDecoder;

    public class Main {

    public static void main(String args) {
    // TODO Auto-generated method stub

    System.out.println( "spark started!" );

    SparkConf conf = new SparkConf()
    .setAppName("kafka-sandbox")
    .setMaster("local[*]");
    JavaSparkContext sc = new JavaSparkContext(conf);
    JavaStreamingContext ssc = new JavaStreamingContext(sc, new Duration(2000));


    Map<String, String> kafkaParams = new HashMap<String, String>();
    kafkaParams.put("metadata.broker.list", "localhost:9092");
    Set<String> topics = Collections.singleton("speed");

    JavaPairInputDStream<String, String> directKafkaStream = KafkaUtils.createDirectStream(ssc,
    String.class, String.class, StringDecoder.class, StringDecoder.class, kafkaParams, topics);

    directKafkaStream.foreachRDD(rdd -> {
    System.out.println("--- New RDD with " + rdd.partitions().size()
    + " partitions and " + rdd.count() + " records");
    rdd.foreach(record -> System.out.println(record._2));
    });

    System.out.println( "connection completed" );


    ssc.start();

    ssc.awaitTermination();

    System.out.println( "spark ended!" );

    }

    }


    Pom.xml



    <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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.spark_stream</groupId>
    <artifactId>com.spark_stream</artifactId>
    <version>0.0.1-SNAPSHOT</version>


    <dependencies>

    <dependency> <!-- Spark dependency -->
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.10</artifactId>
    <version>1.6.0</version>
    </dependency>

    <dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-streaming_2.10</artifactId>
    <version>1.6.0</version>
    </dependency>

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


    </dependencies>

    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    </project>


    Couldn't find a solution for this error. Any help would be appreciated.










    share|improve this question



























      2












      2








      2








      I'm trying to send message from my kafka producer and stream it in spark streaming. But I'm getting the following error when I run my application on spark submit.



      Error



       Exception in thread "main" java.lang.NoClassDefFoundError: kafka/serializer/StringDecoder
      at com.spark_stream.Main.main(Main.java:37)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:736)
      at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
      at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
      at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
      at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
      Caused by: java.lang.ClassNotFoundException: kafka.serializer.StringDecoder
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 10 more


      Application code is as follows:



      Main.java



      package com.spark_stream;

      import java.util.Collections;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.Set;

      import org.apache.spark.SparkConf;
      import org.apache.spark.api.java.JavaSparkContext;
      import org.apache.spark.streaming.Duration;
      import org.apache.spark.streaming.api.java.JavaPairInputDStream;
      import org.apache.spark.streaming.api.java.JavaStreamingContext;
      import org.apache.spark.streaming.kafka.KafkaUtils;

      import kafka.serializer.StringDecoder;

      public class Main {

      public static void main(String args) {
      // TODO Auto-generated method stub

      System.out.println( "spark started!" );

      SparkConf conf = new SparkConf()
      .setAppName("kafka-sandbox")
      .setMaster("local[*]");
      JavaSparkContext sc = new JavaSparkContext(conf);
      JavaStreamingContext ssc = new JavaStreamingContext(sc, new Duration(2000));


      Map<String, String> kafkaParams = new HashMap<String, String>();
      kafkaParams.put("metadata.broker.list", "localhost:9092");
      Set<String> topics = Collections.singleton("speed");

      JavaPairInputDStream<String, String> directKafkaStream = KafkaUtils.createDirectStream(ssc,
      String.class, String.class, StringDecoder.class, StringDecoder.class, kafkaParams, topics);

      directKafkaStream.foreachRDD(rdd -> {
      System.out.println("--- New RDD with " + rdd.partitions().size()
      + " partitions and " + rdd.count() + " records");
      rdd.foreach(record -> System.out.println(record._2));
      });

      System.out.println( "connection completed" );


      ssc.start();

      ssc.awaitTermination();

      System.out.println( "spark ended!" );

      }

      }


      Pom.xml



      <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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.spark_stream</groupId>
      <artifactId>com.spark_stream</artifactId>
      <version>0.0.1-SNAPSHOT</version>


      <dependencies>

      <dependency> <!-- Spark dependency -->
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.10</artifactId>
      <version>1.6.0</version>
      </dependency>

      <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_2.10</artifactId>
      <version>1.6.0</version>
      </dependency>

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


      </dependencies>

      <properties>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
      </properties>
      </project>


      Couldn't find a solution for this error. Any help would be appreciated.










      share|improve this question
















      I'm trying to send message from my kafka producer and stream it in spark streaming. But I'm getting the following error when I run my application on spark submit.



      Error



       Exception in thread "main" java.lang.NoClassDefFoundError: kafka/serializer/StringDecoder
      at com.spark_stream.Main.main(Main.java:37)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:736)
      at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
      at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
      at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
      at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
      Caused by: java.lang.ClassNotFoundException: kafka.serializer.StringDecoder
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 10 more


      Application code is as follows:



      Main.java



      package com.spark_stream;

      import java.util.Collections;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.Set;

      import org.apache.spark.SparkConf;
      import org.apache.spark.api.java.JavaSparkContext;
      import org.apache.spark.streaming.Duration;
      import org.apache.spark.streaming.api.java.JavaPairInputDStream;
      import org.apache.spark.streaming.api.java.JavaStreamingContext;
      import org.apache.spark.streaming.kafka.KafkaUtils;

      import kafka.serializer.StringDecoder;

      public class Main {

      public static void main(String args) {
      // TODO Auto-generated method stub

      System.out.println( "spark started!" );

      SparkConf conf = new SparkConf()
      .setAppName("kafka-sandbox")
      .setMaster("local[*]");
      JavaSparkContext sc = new JavaSparkContext(conf);
      JavaStreamingContext ssc = new JavaStreamingContext(sc, new Duration(2000));


      Map<String, String> kafkaParams = new HashMap<String, String>();
      kafkaParams.put("metadata.broker.list", "localhost:9092");
      Set<String> topics = Collections.singleton("speed");

      JavaPairInputDStream<String, String> directKafkaStream = KafkaUtils.createDirectStream(ssc,
      String.class, String.class, StringDecoder.class, StringDecoder.class, kafkaParams, topics);

      directKafkaStream.foreachRDD(rdd -> {
      System.out.println("--- New RDD with " + rdd.partitions().size()
      + " partitions and " + rdd.count() + " records");
      rdd.foreach(record -> System.out.println(record._2));
      });

      System.out.println( "connection completed" );


      ssc.start();

      ssc.awaitTermination();

      System.out.println( "spark ended!" );

      }

      }


      Pom.xml



      <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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.spark_stream</groupId>
      <artifactId>com.spark_stream</artifactId>
      <version>0.0.1-SNAPSHOT</version>


      <dependencies>

      <dependency> <!-- Spark dependency -->
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.10</artifactId>
      <version>1.6.0</version>
      </dependency>

      <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_2.10</artifactId>
      <version>1.6.0</version>
      </dependency>

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


      </dependencies>

      <properties>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
      </properties>
      </project>


      Couldn't find a solution for this error. Any help would be appreciated.







      java maven apache-kafka spark-streaming spark-submit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 7 '18 at 13:17









      cricket_007

      83k1145113




      83k1145113










      asked Mar 2 '17 at 21:38









      Gaurav RamGaurav Ram

      75731225




      75731225
























          3 Answers
          3






          active

          oldest

          votes


















          2














          Have a look at the doc: http://spark.apache.org/docs/latest/submitting-applications.html#launching-applications-with-spark-submit



          More specifically the part:




          Path to a bundled jar including your application and all dependencies.




          Whereas your pom.xml clearly shows that the jar you are building is without the dependencies. That's why spark-submit cannot find the class kafka.serializer.StringDecoder.



          What you might want to use to solve such a problem is a plugin that include your dependencies inside your jar, the maven assembly plugin can help you with this






          share|improve this answer
























          • Thanks, adding maven assembly plugin did the job.

            – Gaurav Ram
            Mar 4 '17 at 16:24



















          1














          Seems like complier is unable to find kafka jars as you had not included in pom file.
          Trying adding below dependency in your pom file.Check for kafka version you are using.



          <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka_2.10 -->
          <dependency>
          <groupId>org.apache.kafka</groupId>
          <artifactId>kafka_2.10</artifactId>
          <version>0.8.0</version>
          </dependency>





          share|improve this answer



















          • 1





            Am getting same error after adding this dependecy

            – Gaurav Ram
            Mar 3 '17 at 19:28











          • This should be the kafka-clients package anyway

            – cricket_007
            Sep 7 '18 at 13:17



















          0














          This usually happens if you don't bundle all your dependent assemblies that your application needs, try to build a uber which contains all the dependencies.



          I have added a portion of the sample pom file which will do the same.



          <build>
          <sourceDirectory>src/main/scala</sourceDirectory>
          <plugins>
          <plugin>
          <groupId>net.alchim31.maven</groupId>
          <artifactId>scala-maven-plugin</artifactId>
          <version>3.1.6</version>
          <executions>
          <execution>
          <phase>compile</phase>
          <goals>
          <goal>compile</goal>
          <goal>testCompile</goal>
          </goals>
          </execution>
          </executions>
          </plugin>

          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>2.3</version>
          <executions>
          <execution>
          <phase>package</phase>
          <goals>
          <goal>shade</goal>
          </goals>
          <configuration>
          <shadedArtifactAttached>true</shadedArtifactAttached>
          <filters>
          <filter>
          <artifact>*:*</artifact>
          <excludes>
          <exclude>META-INF/*.SF</exclude>
          <exclude>META-INF/*.DSA</exclude>
          <exclude>META-INF/*.RSA</exclude>
          </excludes>
          </filter>
          </filters>
          <artifactSet>
          <includes>
          <include>*:*</include>
          </includes>
          </artifactSet>
          <transformers>
          <transformer
          implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
          <resource>reference.conf</resource>
          </transformer>
          </transformers>
          </configuration>
          </execution>
          </executions>
          </plugin>

          </plugins>





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42566479%2fspark-kafka-streaming-noclassdeffounderror-kafka-serializer-stringdecoder%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Have a look at the doc: http://spark.apache.org/docs/latest/submitting-applications.html#launching-applications-with-spark-submit



            More specifically the part:




            Path to a bundled jar including your application and all dependencies.




            Whereas your pom.xml clearly shows that the jar you are building is without the dependencies. That's why spark-submit cannot find the class kafka.serializer.StringDecoder.



            What you might want to use to solve such a problem is a plugin that include your dependencies inside your jar, the maven assembly plugin can help you with this






            share|improve this answer
























            • Thanks, adding maven assembly plugin did the job.

              – Gaurav Ram
              Mar 4 '17 at 16:24
















            2














            Have a look at the doc: http://spark.apache.org/docs/latest/submitting-applications.html#launching-applications-with-spark-submit



            More specifically the part:




            Path to a bundled jar including your application and all dependencies.




            Whereas your pom.xml clearly shows that the jar you are building is without the dependencies. That's why spark-submit cannot find the class kafka.serializer.StringDecoder.



            What you might want to use to solve such a problem is a plugin that include your dependencies inside your jar, the maven assembly plugin can help you with this






            share|improve this answer
























            • Thanks, adding maven assembly plugin did the job.

              – Gaurav Ram
              Mar 4 '17 at 16:24














            2












            2








            2







            Have a look at the doc: http://spark.apache.org/docs/latest/submitting-applications.html#launching-applications-with-spark-submit



            More specifically the part:




            Path to a bundled jar including your application and all dependencies.




            Whereas your pom.xml clearly shows that the jar you are building is without the dependencies. That's why spark-submit cannot find the class kafka.serializer.StringDecoder.



            What you might want to use to solve such a problem is a plugin that include your dependencies inside your jar, the maven assembly plugin can help you with this






            share|improve this answer













            Have a look at the doc: http://spark.apache.org/docs/latest/submitting-applications.html#launching-applications-with-spark-submit



            More specifically the part:




            Path to a bundled jar including your application and all dependencies.




            Whereas your pom.xml clearly shows that the jar you are building is without the dependencies. That's why spark-submit cannot find the class kafka.serializer.StringDecoder.



            What you might want to use to solve such a problem is a plugin that include your dependencies inside your jar, the maven assembly plugin can help you with this







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 2 '17 at 23:02









            AdonisAdonis

            2,95822035




            2,95822035













            • Thanks, adding maven assembly plugin did the job.

              – Gaurav Ram
              Mar 4 '17 at 16:24



















            • Thanks, adding maven assembly plugin did the job.

              – Gaurav Ram
              Mar 4 '17 at 16:24

















            Thanks, adding maven assembly plugin did the job.

            – Gaurav Ram
            Mar 4 '17 at 16:24





            Thanks, adding maven assembly plugin did the job.

            – Gaurav Ram
            Mar 4 '17 at 16:24













            1














            Seems like complier is unable to find kafka jars as you had not included in pom file.
            Trying adding below dependency in your pom file.Check for kafka version you are using.



            <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka_2.10 -->
            <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.10</artifactId>
            <version>0.8.0</version>
            </dependency>





            share|improve this answer



















            • 1





              Am getting same error after adding this dependecy

              – Gaurav Ram
              Mar 3 '17 at 19:28











            • This should be the kafka-clients package anyway

              – cricket_007
              Sep 7 '18 at 13:17
















            1














            Seems like complier is unable to find kafka jars as you had not included in pom file.
            Trying adding below dependency in your pom file.Check for kafka version you are using.



            <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka_2.10 -->
            <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.10</artifactId>
            <version>0.8.0</version>
            </dependency>





            share|improve this answer



















            • 1





              Am getting same error after adding this dependecy

              – Gaurav Ram
              Mar 3 '17 at 19:28











            • This should be the kafka-clients package anyway

              – cricket_007
              Sep 7 '18 at 13:17














            1












            1








            1







            Seems like complier is unable to find kafka jars as you had not included in pom file.
            Trying adding below dependency in your pom file.Check for kafka version you are using.



            <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka_2.10 -->
            <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.10</artifactId>
            <version>0.8.0</version>
            </dependency>





            share|improve this answer













            Seems like complier is unable to find kafka jars as you had not included in pom file.
            Trying adding below dependency in your pom file.Check for kafka version you are using.



            <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka_2.10 -->
            <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.10</artifactId>
            <version>0.8.0</version>
            </dependency>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 3 '17 at 9:43









            Ayush PandeyAyush Pandey

            1386




            1386








            • 1





              Am getting same error after adding this dependecy

              – Gaurav Ram
              Mar 3 '17 at 19:28











            • This should be the kafka-clients package anyway

              – cricket_007
              Sep 7 '18 at 13:17














            • 1





              Am getting same error after adding this dependecy

              – Gaurav Ram
              Mar 3 '17 at 19:28











            • This should be the kafka-clients package anyway

              – cricket_007
              Sep 7 '18 at 13:17








            1




            1





            Am getting same error after adding this dependecy

            – Gaurav Ram
            Mar 3 '17 at 19:28





            Am getting same error after adding this dependecy

            – Gaurav Ram
            Mar 3 '17 at 19:28













            This should be the kafka-clients package anyway

            – cricket_007
            Sep 7 '18 at 13:17





            This should be the kafka-clients package anyway

            – cricket_007
            Sep 7 '18 at 13:17











            0














            This usually happens if you don't bundle all your dependent assemblies that your application needs, try to build a uber which contains all the dependencies.



            I have added a portion of the sample pom file which will do the same.



            <build>
            <sourceDirectory>src/main/scala</sourceDirectory>
            <plugins>
            <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.1.6</version>
            <executions>
            <execution>
            <phase>compile</phase>
            <goals>
            <goal>compile</goal>
            <goal>testCompile</goal>
            </goals>
            </execution>
            </executions>
            </plugin>

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
            <execution>
            <phase>package</phase>
            <goals>
            <goal>shade</goal>
            </goals>
            <configuration>
            <shadedArtifactAttached>true</shadedArtifactAttached>
            <filters>
            <filter>
            <artifact>*:*</artifact>
            <excludes>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
            <exclude>META-INF/*.RSA</exclude>
            </excludes>
            </filter>
            </filters>
            <artifactSet>
            <includes>
            <include>*:*</include>
            </includes>
            </artifactSet>
            <transformers>
            <transformer
            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>reference.conf</resource>
            </transformer>
            </transformers>
            </configuration>
            </execution>
            </executions>
            </plugin>

            </plugins>





            share|improve this answer




























              0














              This usually happens if you don't bundle all your dependent assemblies that your application needs, try to build a uber which contains all the dependencies.



              I have added a portion of the sample pom file which will do the same.



              <build>
              <sourceDirectory>src/main/scala</sourceDirectory>
              <plugins>
              <plugin>
              <groupId>net.alchim31.maven</groupId>
              <artifactId>scala-maven-plugin</artifactId>
              <version>3.1.6</version>
              <executions>
              <execution>
              <phase>compile</phase>
              <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
              </goals>
              </execution>
              </executions>
              </plugin>

              <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>2.3</version>
              <executions>
              <execution>
              <phase>package</phase>
              <goals>
              <goal>shade</goal>
              </goals>
              <configuration>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <filters>
              <filter>
              <artifact>*:*</artifact>
              <excludes>
              <exclude>META-INF/*.SF</exclude>
              <exclude>META-INF/*.DSA</exclude>
              <exclude>META-INF/*.RSA</exclude>
              </excludes>
              </filter>
              </filters>
              <artifactSet>
              <includes>
              <include>*:*</include>
              </includes>
              </artifactSet>
              <transformers>
              <transformer
              implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>reference.conf</resource>
              </transformer>
              </transformers>
              </configuration>
              </execution>
              </executions>
              </plugin>

              </plugins>





              share|improve this answer


























                0












                0








                0







                This usually happens if you don't bundle all your dependent assemblies that your application needs, try to build a uber which contains all the dependencies.



                I have added a portion of the sample pom file which will do the same.



                <build>
                <sourceDirectory>src/main/scala</sourceDirectory>
                <plugins>
                <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.1.6</version>
                <executions>
                <execution>
                <phase>compile</phase>
                <goals>
                <goal>compile</goal>
                <goal>testCompile</goal>
                </goals>
                </execution>
                </executions>
                </plugin>

                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                <execution>
                <phase>package</phase>
                <goals>
                <goal>shade</goal>
                </goals>
                <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <filters>
                <filter>
                <artifact>*:*</artifact>
                <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
                </excludes>
                </filter>
                </filters>
                <artifactSet>
                <includes>
                <include>*:*</include>
                </includes>
                </artifactSet>
                <transformers>
                <transformer
                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                <resource>reference.conf</resource>
                </transformer>
                </transformers>
                </configuration>
                </execution>
                </executions>
                </plugin>

                </plugins>





                share|improve this answer













                This usually happens if you don't bundle all your dependent assemblies that your application needs, try to build a uber which contains all the dependencies.



                I have added a portion of the sample pom file which will do the same.



                <build>
                <sourceDirectory>src/main/scala</sourceDirectory>
                <plugins>
                <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.1.6</version>
                <executions>
                <execution>
                <phase>compile</phase>
                <goals>
                <goal>compile</goal>
                <goal>testCompile</goal>
                </goals>
                </execution>
                </executions>
                </plugin>

                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                <execution>
                <phase>package</phase>
                <goals>
                <goal>shade</goal>
                </goals>
                <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <filters>
                <filter>
                <artifact>*:*</artifact>
                <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
                </excludes>
                </filter>
                </filters>
                <artifactSet>
                <includes>
                <include>*:*</include>
                </includes>
                </artifactSet>
                <transformers>
                <transformer
                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                <resource>reference.conf</resource>
                </transformer>
                </transformers>
                </configuration>
                </execution>
                </executions>
                </plugin>

                </plugins>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 5:26









                skjaginiskjagini

                1,30621637




                1,30621637






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42566479%2fspark-kafka-streaming-noclassdeffounderror-kafka-serializer-stringdecoder%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word