简体   繁体   English

scala 2.12 NoClassDefFoundError: scala/Product$class 原因:ClassNotFoundException: scala.Product$class

[英]scala 2.12 NoClassDefFoundError: scala/Product$class Caused by: ClassNotFoundException: scala.Product$class

I have getting this error when I execute the scala code using Jar file.当我使用 Jar 文件执行 scala 代码时出现此错误。 Below versions used使用以下版本

scala version: 2.12 and sbt: 1.7.1 scala 版本:2.12 和 sbt:1.7.1
spark: 3.1.2.火花:3.1.2。 java - jdk 1.8.0_331 java-jdk 1.8.0_331

Error: NoClassDefFoundError: scala/Product$class Caused by: ClassNotFoundException: scala.Product$class错误:NoClassDefFoundError:scala/Product$class 原因:ClassNotFoundException:scala.Product$class

dependent library used in sbt.build: sbt.build 中使用的依赖库:

"org.apache.spark" %% "spark-core" % "3.1.2" %"provided",
"org.apache.spark" %% "spark-sql" % "3.1.2" %"provided",
"commons-validator" % "commons-validator" % "1.6",
"org.elasticsearch" %% "elasticsearch-spark-20" % "7.14.1",   
"com.github.pureconfig" %% "pureconfig" % "0.12.3",
"org.rogach" %% "scallop" % "3.5.0",
"com.github.dwickern" %% "scala-nameof" % "1.0.3" ,
"com.sksamuel.elastic4s" %% "elastic4s-core" % "7.14.1",
"com.sksamuel.elastic4s" %% "elastic4s-client-esjava" % "7.14.1",
"com.sksamuel.elastic4s" %% "elastic4s-http-streams" % "7.14.1",
"com.sksamuel.elastic4s" %% "elastic4s-testkit" % "7.14.1" % "test",
"com.databricks" % "dbutils-api_2.11" % "0.0.4"

Tried multiple ways do not get the solution yet.尝试了多种方法还没有得到解决方案。 any help much apreciated.非常感谢任何帮助。

Thanks谢谢

dbutils-api_2.11 is compiled for Scala 2.11, and is not compatible with Scala 2.12. dbutils-api_2.11是为 Scala 2.11 编译的,与 Scala 2.12 不兼容。 You should use dbutils-api_2.12 if that exists, or otherwise just not use that library.如果存在,您应该使用dbutils-api_2.12 ,否则就不要使用该库。

For Scala libraries you should use the %% syntax to avoid these kinds of issues:对于 Scala 库,您应该使用%%语法来避免这些问题:

"com.databricks" %% "dbutils-api" % "0.0.4"

Now the correct suffix will be added automatically by sbt.现在 sbt 将自动添加正确的后缀。

On mvnrepository you can see which versions are available.mvnrepository 上,您可以查看可用的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM