【发布时间】:2019-07-10 09:16:48
【问题描述】:
我是 Scala 初学者,正在 Maven 上运行一个入门项目并使用 IntelliJ 作为 IDE。
这是我正在使用Github project 的 github 上项目的链接,我针对 OpenJDK8 编译了该项目。
HelloJava 类运行成功,但是,当我尝试运行 HelloScala 类时遇到以下错误:
java -cp scala-maven-example-1.0.0-SNAPSHOT.jar com.jesperdj.example.HelloScala
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function0
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:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: scala.Function0
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
【问题讨论】:
-
您可能需要在运行
java时将Scala 运行时包附加到-cp参数中。 -
哦。我试过了,它有效。如果您提出正确的答案,我会选择正确的。谢谢!
-
我猜你的问题标题更多的是关于在 Intellij 上运行 Scala?
-
@sudeepgupta90 我发布了一个稍微详细的答案。
标签: scala maven intellij-idea