MapDB ClassNotFoundException: kotlin.jvm.internal.Intrinsics

后端 未结 4 1422
无人共我
无人共我 2020-12-17 03:36

I am trying to run a simple mapdb example, but get the error:

    Exception in thread \"main\" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics         


        
相关标签:
4条回答
  • 2020-12-17 04:25

    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/*"
    
    0 讨论(0)
  • 2020-12-17 04:33

    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

    0 讨论(0)
  • 2020-12-17 04:36

    Maybe run your class from maven, it will add all necessary dependencies.

    run main class of Maven project

    0 讨论(0)
  • 2020-12-17 04:37

    @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):

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    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.

    0 讨论(0)
提交回复
热议问题