Scala / Spark:NoClassDefFoundError:net / liftweb / json / Formats

时间:2016-09-21 16:35:24

标签: json scala apache-spark lift-json

我正在尝试从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)

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

1 个答案:

答案 0 :(得分:1)

  

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

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