MapDB ClassNotFoundException: kotlin.jvm.internal.Intrinsics

Tyvain picture Tyvain · Apr 15, 2017 · Viewed 11k times · Source

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.

Answer

prayagupd picture prayagupd · Jun 24, 2017

Either kotlin-runtime has to be in classpath and verify with $ echo $CLASSPATH.

Or you have to add kotlin-runtime to maven and then assemble inside the jar itself with mvn compile assembly:single,

<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-runtime</artifactId>
    <version>1.1.3</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib</artifactId>
    <version>1.1.3</version>
    <scope>compile</scope>
</dependency>

which need to be attached to artifact as well and can be done with assembly-plugin.

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>event.handlers.InventoryEventHandler</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>

you can verify the kotlin-runtime is added to jar by

$ jar -tf target/amz-wavelength-1.0-SNAPSHOT-jar-with-dependencies.jar | grep kotlin-runtime
META-INF/kotlin-runtime.kotlin_module

or

$ jar -tf target/amz-wavelength-1.0-SNAPSHOT-jar-with-dependencies.jar | grep "kotlin/jvm/internal/*"