I have a scala app with an object
which implements def main(args:Array[String]): Unit
trait. I use the sbtAssembly
plugin to create a fat jar, and I can run it from the console using:
scala myjar.jar
However, I want to hand this over to colleagues who don't have scala installed, but only the jdk/jre. So I tried to run this with java, however it fails:
java -jar myjar.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/Seq
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: scala.collection.Seq
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
What do I have to do in order to be able to run it with java
? Is this even possible?
To run a jar using just java -jar
without specifying a classpath, it must include all dependencies, including the standard Scala library (and from the error message we can see that's what's missing). By default sbt-assembly includes it, but it can be configured to exclude it and that's what your build does. Simply remove includeScala = false
(or set it to true
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.