Java Eclipse scala.object 无法解析
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22102257/
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
Eclipse scala.object cannot be resolved
提问by B.Mr.W.
I am trying to write Kafka producer and consumer code in Java using Eclipse. I am have downloaded the Kafka jar file and loaded as external Jar file. And it solved the dependency problem.
我正在尝试使用 Eclipse 用 Java 编写 Kafka 生产者和消费者代码。我已经下载了 Kafka jar 文件并作为外部 Jar 文件加载。它解决了依赖问题。
However, there is always a unresolved error and the message looks like below:
但是,始终存在未解决的错误,消息如下所示:
Multiple markers at this line
- The type scala.Product cannot be resolved. It is indirectly referenced from required .class files
- The type scala.Serializable cannot be resolved. It is indirectly referenced from required .class
files
I really don't know what is going on and how to fix that error. Thanks.
我真的不知道发生了什么以及如何修复该错误。谢谢。
采纳答案by Mike Allen
UPDATED 4/26/2018
2018 年 4 月 26 日更新
It appears that you need to have the Scalaruntime library in your Eclipseproject's classpath.
看来您需要在Eclipse项目的类路径中有Scala运行时库。
If you're using Maven(or some other repository-based build tool—highly recommended), then adding Kafkaas a dependency should cause it to automatically download the corresponding Scalaruntime library and include it on your project's classpath. For example,
如果您正在使用Maven(或其他一些基于存储库的构建工具 - 强烈推荐),那么将Kafka添加为依赖项应该会使其自动下载相应的Scala运行时库并将其包含在您项目的类路径中。例如,
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.12</artifactId>
<version>1.1.0</version>
</dependency>
will cause Mavento download version 2.12.4 of the Scalaruntime library.
将导致Maven下载Scala运行时库的2.12.4 版。
Otherwise, you can install Scala (see http://scala-lang.org/) and add the installed scala-library.jar to your project's classpath manually. However, you should note that Scalaminor releases (2.10.x, 2.11.x, 2.12.x, etc.) are not binary compatible with each other, so you should download the most recent bug-fix version of the minor release used to build your version of Kafka. (This minor version is appended to the name of the Kafkaartifact, e.g. kafka_2.12 requires a Scala2.12.x runtime library version.)
否则,您可以安装 Scala(参见http://scala-lang.org/)并手动将安装的 scala-library.jar 添加到您的项目的类路径中。但是,您应该注意Scala次要版本(2.10.x、2.11.x、2.12.x 等)彼此之间不是二进制兼容的,因此您应该下载用于使用的次要版本的最新错误修复版本。构建您的Kafka版本。(此次要版本附加到Kafka工件的名称后,例如 kafka_2.12 需要Scala2.12.x 运行时库版本。)
回答by mannedear
Downloaded the scala libraries from http://scala-lang.org/download/and added the scala-library.jar to the project, error resolved!
从http://scala-lang.org/download/下载了 scala 库并将 scala-library.jar 添加到项目中,错误解决!
回答by user12832610
Delete the unneccessary jar
files and keep exact version jar
file. It worked for me.
删除不需要的jar
文件并保留准确的版本jar
文件。它对我有用。