Exception
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: scala/runtime/java8/JFunction1$mcII$sp
at SparkPi$.main(SparkPi.scala:14)
at SparkPi.main(SparkPi.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Problem:
It seems that you have compiled and generated your jar file with an upper version of the Scala compiler than the one spark is using.
Solution
Step 1
Run the following command from spark-installed-directory\binspark-shell.cmd (or.sh)
and note the Scala version, My Spark version was 2.4.3 and Scala version 2.11.12
Step 2
Change the scala version into your build.sbt to 2.11.12 (per your configuration).My build.sbt is
name := "SparkPi Project"
version := "1.0"
scalaVersion := "2.11.12"
val sparkVersion = "2.4.5"
libraryDependencies += "org.apache.spark" %% "spark-core" % sparkVersion % "provided"
Now when you submit you jar to Spark, it will run without errors.
Hope you find this post helpful.

Scala version compatibility is an important consideration when deploying Apache Spark applications. The NoClassDefFoundError involving scala/runtime/java8/JFunction1$mcII$sp can occur when an application is compiled against a different Scala version than the one used by the Spark runtime. Checking the Scala version reported by spark-shell and aligning the project's Scala compiler and dependencies with the installed Spark distribution is a good first troubleshooting step.
ReplyDeleteFor developers interested in learning distributed data processing with Python, PySpark Online Training in India is a relevant learning resource. Understanding Spark's runtime environment, dependencies, and execution model helps developers troubleshoot compatibility issues more effectively.
Additionally, Data Engineering Online Training in India can help learners develop a broader understanding of data processing frameworks and pipeline architecture. Building a solid foundation in these areas is valuable when developing, deploying, and maintaining reliable big data applications.
ReplyDelete