【问题标题】:Scala/Spark: NoClassDefFoundError: net/liftweb/json/FormatsScala/Spark:NoClassDefFoundError:net/liftweb/json/Formats
【发布时间】:2016-11-26 11:51:02
【问题描述】:

我正在尝试从 Scala 对象创建 JSON 字符串,如 here 所述。

我有以下代码:

import scala.collection.mutable._
import net.liftweb.json._
import net.liftweb.json.Serialization.write

case class Person(name: String, address: Address)
case class Address(city: String, state: String)

object LiftJsonTest extends App {

  val p = Person("Alvin Alexander", Address("Talkeetna", "AK"))

  // create a JSON string from the Person, then print it
  implicit val formats = DefaultFormats
  val jsonString = write(p)
  println(jsonString)

}

我的 build.sbt 文件包含以下内容:

libraryDependencies += "net.liftweb" %% "lift-json" % "2.5+"

当我使用sbt package 构建时,它是成功的。

但是,当我尝试将其作为 Spark 作业运行时,如下所示:

spark-submit \
  --packages com.amazonaws:aws-java-sdk-pom:1.10.34,org.apache.hadoop:hadoop-aws:2.6.0,net.liftweb:lift-json:2.5+ \
  --class "com.foo.MyClass" \
  --master local[4] \
  target/scala-2.10/my-app_2.10-0.0.1.jar

我收到此错误:

Exception in thread "main" java.lang.RuntimeException: [unresolved dependency: net.liftweb#lift-json;2.5+: not found]
    at org.apache.spark.deploy.SparkSubmitUtils$.resolveMavenCoordinates(SparkSubmit.scala:1068)
    at org.apache.spark.deploy.SparkSubmit$.prepareSubmitEnvironment(SparkSubmit.scala:287)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:154)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

我在这里做错了什么?我的packages 参数中的net.liftweb:lift-json:2.5+ 是否不正确?是否需要在 build.sbt 中添加解析器?

【问题讨论】:

    标签: json scala apache-spark lift-json


    【解决方案1】:

    Users may also include any other dependencies by supplying a comma-delimited list of maven coordinates with --packages.

    build.sbt 中的2.5+Ivy version matcher 语法,而不是Maven 坐标所需的实际工件版本。 spark-submit 显然不使用 Ivy 进行解析(我认为如果这样做会令人惊讶;由于发布了新的依赖版本,您的应用程序可能会突然停止工作)。因此,您需要找到 2.5+ 在您的情况下解析为的版本,例如使用https://github.com/jrudolph/sbt-dependency-graph(或尝试在show dependencyClasspath 中找到它)。

    【讨论】:

    • 这里最好的解决方案是使用lift-json的最新发布版本,即2.6.3。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多