Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

local class incompatible Exception: when running spark standalone from IDE

I begin to test spark. I installed spark on my local machine and run a local cluster with a single worker. when I tried to execute my job from my IDE by setting the sparconf as follows:

final SparkConf conf = new SparkConf().setAppName("testSparkfromJava").setMaster("spark://XXXXXXXXXX:7077");
final JavaSparkContext sc = new JavaSparkContext(conf);
final JavaRDD<String> distFile = sc.textFile(Paths.get("").toAbsolutePath().toString() + "dataSpark/datastores.json");*

I got this exception:

java.lang.RuntimeException: java.io.InvalidClassException: org.apache.spark.rpc.netty.RequestMessage; local class incompatible: stream classdesc serialVersionUID = -5447855329526097695, local class serialVersionUID = -2221986757032131007
like image 712
Nesrine Ben mustapha Avatar asked Feb 18 '16 15:02

Nesrine Ben mustapha


People also ask

How do I run spark in local mode?

So, how do you run the spark in local mode? It is very simple. When we do not specify any --master flag to the command spark-shell, pyspark, spark-submit, or any other binary, it is running in local mode. Or we can specify --master option with local as argument which defaults to 1 thread.

Can Spark be run locally?

It's easy to run locally on one machine — all you need is to have java installed on your system PATH , or the JAVA_HOME environment variable pointing to a Java installation. Spark runs on Java 8/11/17, Scala 2.12/2.13, Python 3.7+ and R 3.5+.

What is a spark core?

Spark Core is the underlying general execution engine for the Spark platform that all other functionality is built on top of. It provides in-memory computing capabilities to deliver speed, a generalized execution model to support a wide variety of applications, and Java, Scala, and Python APIs for ease of development.


2 Answers

It can be multiple incompatible reasons below:

  • Hadoop version;
  • Spark version;
  • Scala version;
  • ...

For me, its Scala version , I using 2.11.X in my IDE but official doc says:

Spark runs on Java 7+, Python 2.6+ and R 3.1+. For the Scala API, Spark 1.6.1 uses Scala 2.10. You will need to use a compatible Scala version (2.10.x).

and the x in the doc told cannot be smaller than 3 if you using latest Java(1.8), cause this. Hope it will help you!

like image 168
Kun Avatar answered Sep 19 '22 15:09

Kun


Got it all working with below combination of versions

Installed spark 1.6.2

verify with bin/spark-submit --version

<dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.10</artifactId>
            <version>1.6.2</version>
</dependency>

and

Scala 2.10.6 and Java 8.

Note it did NOT work and have similar class incompatible issue with below versions

Scala 2.11.8 and Java 8

<dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>1.6.2</version>
</dependency>
like image 43
user1733158 Avatar answered Sep 20 '22 15:09

user1733158