我有一個scala項目,我已經使用sbt包構建並運行到目前爲止。現在我需要將它們移植到另一臺機器上。因此,我可以看到,JAR文件java.lang.NoClassDefFoundError:從Scala運行JAR時
$PROJECT_HOME/target/scala-2.9.3/My-app_2.9.3-1.0.jar
下創建但是,當我嘗試使用運行它們,
java -jar target/scala-2.9.3/My-app_2.9.3-1.0.jar
錯誤信息是這樣的,
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/SparkContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.SparkContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
我得到java.lang.NoClassDefFoundError:org/apache/spark/SparkContext異常。我知道如果JAR找不到/加載類的定義,通常會發生NoClassDefFoundError。但在我的sbt我已包括類,
name := "My App"
version := "1.0"
scalaVersion := "2.9.3"
libraryDependencies += "org.apache.spark" %% "spark-core" % "0.8.0-incubating"
任何錯誤的原因指針將不勝感激?謝謝!
http://javareferencegv.blogspot.com/2013/10/debugging-javalangnoclassdeffounderror.html –