SBT:添加第三方库依赖项但NoClassDefFoundError

时间:2015-03-19 01:26:54

标签: java scala sbt apache-spark

我使用sbt来构建我的Scala项目。

这是我的build.sbt文件:

name := "SpatialSpark"

version := "1.0"

scalaVersion := "2.10.4"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.2.1"

libraryDependencies += "com.vividsolutions" % "jts" % "1.13"

然后我尝试将它打包到jar中。 sbt package

最后,我将其提交给Apache-Spark

spark-submit --class "com.chen.spatial.SpatialApp" --master local[4] target/scala-2.10/spatialspark_2.10-1.0.jar 

导致 NoClassDefFoundError 错误,

Exception in thread "main" java.lang.NoClassDefFoundError: com/vividsolutions/jts/index/strtree/STRtree

将它装入罐子时,我有没有想念?

2 个答案:

答案 0 :(得分:1)

您应该在运行

后创建uber jar
sbt assembly

它应该有用

答案 1 :(得分:1)

请查看此模板项目:

https://github.com/spektom/spark-scala-template

建立uberjar运行:

var http = new Http(..)

在Spark中运行Jar:

sbt assembly