Appleshell
Appleshell

Reputation: 7388

ClassNotFoundException / NoClassDefFoundError when running a Scala jar

Having a Scala project exported to a .jar with eclipse, the application started with java -jar app.jar dies with the error java.lang.ClassNotFoundException: scala.Predef$.

Full output:

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

The referenced line at main.App$.debug(App.scala:69):

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

This seems to be caused because the Scala libraries are not contained in the jar. How do I fix this?

I have read about solutions with maven plugins but I would prefer a manual option.

Upvotes: 1

Views: 2070

Answers (1)

Garry
Garry

Reputation: 306

Manually push the libs there in jar.. or you have good option to script it down

Upvotes: 2

Related Questions