I am trying to run a simple mapdb example, but get the error:
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at org.mapdb.DBMaker.fileDB(DBMaker.kt)
at leechies.Truc.main(Truc.java:9)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
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)
... 2 more
My class:
package leechies;
import java.util.concurrent.ConcurrentMap;
import org.mapdb.DB;
import org.mapdb.DBMaker;
public class Truc {
public static void main(String[] args) {
DB db = DBMaker.fileDB("file.db").make();
ConcurrentMap map = db.hashMap("map").createOrOpen();
map.put("something", "here");
db.close();
}
}
My pomx.xml
<dependencies>
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
<version>3.0.3</version>
</dependency>
I run with rigth click -> Run as... -> java application.
Maybe run your class from maven, it will add all necessary dependencies.
run main class of Maven project
Either
kotlin-runtime
has to be inclasspath
and verify with$ echo $CLASSPATH
.Or you have to add
kotlin-runtime
to maven and then assemble inside the jar itself withmvn compile assembly:single
,which need to be attached to artifact as well and can be done with
assembly-plugin
.you can verify the kotlin-runtime is added to jar by
or
@prayagupd's answer works for me. But I thought it worth mentioning that another option is to use the maven-shade-plugin instead of the maven-assembly-plugin (put this in the
build/plugins
section of your pom.xml file):The shade plugin is nice because it allows you to exclude duplicate classes. If you have to use either plugin, it's good to know you don't need both. Build time and resulting jar file sizes are nearly identical in my quick tests, but the assembly plugin (that prayagupd suggested) doesn't add a bunch of warnings to my build output, so I'm going with that.
It will fail because you do not have the necessary kotlin runtime jar in your classpath. You have to run some command to resolve this error. please refer this link for commands:-
https://dzone.com/articles/exercises-in-kotlin-part-1-getting-started