我正在尝试运行一个简单的mapdb示例,但是得到了错误:
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我的班级:
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();
}
}我的pomx.xml
<dependencies>
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
<version>3.0.3</version>
</dependency>我严格地运行,点击->运行作为.-> java应用程序。
发布于 2017-06-24 07:51:17
要么kotlin-runtime必须在classpath中,然后使用$ echo $CLASSPATH进行验证。
或者您必须将kotlin-runtime添加到maven中,然后使用mvn compile assembly:single在jar内部组装,
<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>它也需要附加到工件上,并且可以用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>您可以通过以下方法验证kotlin运行时添加到jar中。
$ jar -tf target/amz-wavelength-1.0-SNAPSHOT-jar-with-dependencies.jar | grep kotlin-runtime
META-INF/kotlin-runtime.kotlin_module或
$ jar -tf target/amz-wavelength-1.0-SNAPSHOT-jar-with-dependencies.jar | grep "kotlin/jvm/internal/*"发布于 2018-07-11 16:01:07
@prayagupd的答案对我有用。但我认为值得一提的是,另一种选择是使用maven-阴影插件而不是maven-程序集-插件 (将其放在pom.xml文件的build/plugins部分):
<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>阴影插件很不错,因为它允许你排除重复的类。如果你必须使用任何一个插件,这是很好的知道你不需要两者。在我的快速测试中,构建时间和由此产生的jar文件大小几乎是相同的,但是程序集插件( prayagupd建议的)并没有在我的构建输出中添加一堆警告,所以我将这样做。
发布于 2017-04-15 17:10:39
它将失败,因为您的类路径中没有必要的kotlin运行时jar。您必须运行一些命令来解决此错误。有关命令,请参阅此连结:-
https://dzone.com/articles/exercises-in-kotlin-part-1-getting-started
https://stackoverflow.com/questions/43425367
复制相似问题