0

I am trying to create an executable Jar from my Scala project. Therefore, I followed a tutorial. It suggested creating a Java main class within eclipse, which calls the Scala entry point. This works fine when executing within eclipse. After adding this class I was able to export an executable jar. However, it wont work with

java -jar myjar.jar

I made sure to activate "Package required library into jar" when exporting. My Java main class looks like this (where Driver is also located in the package core)

package core;

public class Main {
     public static void main(String[] args) {
        Driver.main(args);
    }
}

And when executing the exported char the follwing error is thrown, which I can debug:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: scala/collection/Seq
    at core.Driver$.main(Driver.scala:14)
    at core.Driver.main(Driver.scala)
    at core.Main.main(Main.java:5)
    ... 5 more
Caused by: java.lang.ClassNotFoundException: scala.collection.Seq
    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:425)

1 Answer 1

1

You could use the One-jar application to guarantee all the necessary jars are in the jarfile, I suspect the scala-lang jars are not in it or in the classpath of the command line.

Maven: https://code.google.com/p/onejar-maven-plugin/ SBT: https://github.com/sbt/sbt-onejar

If you aren't using either maven or SBT I would suggest switching to them as well as they are the main supported build systems in Scala

Sign up to request clarification or add additional context in comments.

1 Comment

I used sbt, not with onejar, but assembly. It worked great and was easy to setup. However, I had some little problems with Maven. To be honest I did not try that hard, since I had sbt already running ;) I accept your answer, however it would be even finer, if others would directly answer my question!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.