Spark - 解决任务执行时报“NoClassDefFoundError: scala/collection/mutable/ArraySeq$ofRef”错误
作者:hangge | 2024-07-24 08:15
1,问题描述
最近使用 Scala 编写了个 Spark 程序,在本地运行是正常的,但打成 Jar 包使用 spark-submit 命令提交到 Spark 集群执行时就报如下错误:
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: scala/collection/mutable/ArraySeq$ofRef
at WordCount$.main(WordCount.scala:19)
at WordCount.main(WordCount.scala)
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.JavaMainApplication.start(SparkApplication.scala:52)
at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:1020)
at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:192)
at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:215)
at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:91)
at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1111)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1120)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.NoClassDefFoundError: scala/collection/mutable/ArraySeq$ofRef
... 14 more
Caused by: java.lang.ClassNotFoundException: scala.collection.mutable.ArraySeq$ofRef
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 14 more
![](http://hangge.com/blog_uploads/202407/2024070514360743720.png)
2,问题原因
(1)通常来说这个是由于我们本地使用的 Scala 版本和服务器不一致。查看 pom.xml 文件可以肯定看到我本地使用的是 2.13 版本的 Scala 进行编译:
![](http://hangge.com/blog_uploads/202407/2024070514385243720.png)
(2)而在服务上使用如下命令查看 Spark 版本信息,可以发现其使用的 Scala 版本为 2.12:
./bin/spark-submit --version
![](http://hangge.com/blog_uploads/202407/2024070514414965646.png)
3,解决办法
修改本地项目的 pom.xml 文件,将 Scala 版本改成和服务器上的一致即可:
![](http://hangge.com/blog_uploads/202407/2024070514430298877.png)
全部评论(0)