运行Scala jar时ClassNotFoundException / NoClassDefFoundError

时间:2013-05-02 14:02:48

标签: scala jar jvm

使用eclipse将Scala项目导出到.jar后,应用程序以java -jar app.jar开头,错误为java.lang.ClassNotFoundException: scala.Predef$

完整输出:

Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:490)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:829)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:150)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoClassDefFoundError: scala/Predef$
    at main.App$.debug(App.scala:69)
    at main.App.start(App.scala:23)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:772)
    at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:260)
    at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:223)
    at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:220)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:220)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:94)
Caused by: java.lang.ClassNotFoundException: scala.Predef$
    at java.net.URLClassLoader$1.run(URLClassLoader.java:365)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:353)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:422)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:355)
    ... 9 more

引用的行at main.App$.debug(App.scala:69)

object App {
//...
    def debug(s: String) {
        println("DEB: "+s)
    }
// ... 
}

这似乎是因为Scala库未包含在jar中。我该如何解决这个问题?

我已经阅读了有关maven插件的解决方案,但我更喜欢手动选项。

1 个答案:

答案 0 :(得分:2)

在jar中手动推送lib ..或者你可以选择将其编入脚本