ClassNotFoundException:scala.PreDef$ 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16821828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 05:20:21  来源:igfitidea点击:

ClassNotFoundException:scala.PreDef$ issue

scalanoclassdeffounderror

提问by Andy

Hi guys I am trying to package a simple executable Jar written in Scala, through Eclipse's Export function.

大家好,我正在尝试通过 Eclipse 的导出功能打包一个用 Scala 编写的简单可执行 Jar。

When attempting to execute the Jar from cmd java -jar test2.jar

尝试从 cmd 执行 Jar 时 java -jar test2.jar

I get the following.... Any ideas? Thank you.

我得到以下....有什么想法吗?谢谢你。

Caused by: java.lang.NoClassDefFoundError: scala/Predef$
        at Parser.Test(Parser.scala:5)
        at Main.main(Main.java:12)
        ... 5 more
Caused by: java.lang.ClassNotFoundException: scala.Predef$
        at java.net.URLClassLoader.run(Unknown Source)
        at java.net.URLClassLoader.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

回答by Régis Jean-Gilles

You just need to add the scala library jar to the classpath.

您只需要将 Scala 库 jar 添加到类路径。

You can do it like this (assuming that the "scala-library.jar" jar is in the current directory) :

您可以这样做(假设“scala-library.jar”jar 在当前目录中):

java -cp scala-library.jar -jar test2.jar

The documentation for tha javacomamnd can be found here: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html

java可以在此处找到该命令的文档:http: //docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html

回答by Shaaban Ebrahim

for me i was using jdk 11 and scala library container 2.12.3 and when i changed to jdk 8 it works fine it is because of jdk11 scala version support JDK Compatibility

对我来说,我使用的是 jdk 11 和 scala 库容器 2.12.3,当我更改为 jdk 8 时它工作正常,这是因为 jdk11 scala 版本支持 JDK 兼容性

right click on the project , Build path ,configure Build path , edit your jdk to less than 11

右键项目,构建路径,配置构建路径,将你的jdk编辑为小于11

回答by rarry

You can also package scala library together with your project. See thispost

您还可以将 Scala 库与您的项目打包在一起。看到这个帖子

回答by Leon Rom

I did removed"Scala Library container" from project. Next - addneeded scala's library (scala-library.jar) to Java BuildPath(in Properties for) as "Add External JARs..." in mylibrary (not as reference to scala lib). And innclude them all to "Order and Export" Finally- do Exportfor project with option "Package required libraries into generate JAR" and this works fine :)

我确实从项目中删除了Scala 库容器”。下一步-添加需要Scala的库(斯卡拉-library.jar)到Java的构建路径(在为属性)为“添加外部JAR ...”在我的库(而不是作为参考斯卡拉LIB)。并将它们全部包含到“订购和导出最后-使用选项“将所需的库打包到生成 JAR 中”为项目进行导出,这很好用:)