-1

I've been trying for some hours to run a generated kotlin jar file but I've been going through an error.

When running java -jar log-reader.jar I get the following exception:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/coroutines/Continuation
        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:650)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: kotlin.coroutines.Continuation
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more

The jar is being generated using mvn package

I have already tried to change kotlin version and my IDEA plugin is already in the 1.3 version. Can anyone help me on this?

Thanks!

  • 1
    It seems the jar you are producing doesn't include the routines library, add the commands you are using to generate the jar so people can backtrack the problem – cutiko Oct 06 '19 at 23:42
  • Thanks for the answer @cutiko! I'm generating the jar through mvn package – Victor Augusto Oct 06 '19 at 23:56

1 Answers1

2

mvn package maven goal only packages your code into a jar, so that it doesn't contain the code of your dependencies required to run the jar.

You should either copy all your dependencies beside the entry-point jar or pack their content into your jar, creating a so called fat jar or an uber jar.

The latter can be achieved with the help of various maven plugins, e.g., maven-assembly-plugin, maven-shade-plugin, etc. You can read more about several ways to achieve it here: https://www.baeldung.com/executable-jar-with-maven.

See also this stackoverflow question about creating a fat jar: Building a fat jar using maven

Ilya
  • 21,871
  • 8
  • 73
  • 92