Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse scala.object cannot be resolved

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.

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.

enter image description here

like image 761
B.Mr.W. Avatar asked Feb 28 '14 17:02

B.Mr.W.


2 Answers

UPDATED 4/26/2018

It appears that you need to have the Scala runtime library in your Eclipse project's classpath.

If you're using Maven (or some other repository-based build tool—highly recommended), then adding Kafka as a dependency should cause it to automatically download the corresponding Scala runtime library and include it on your project's classpath. For example,

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.12</artifactId>
    <version>1.1.0</version>
</dependency>

will cause Maven to download version 2.12.4 of the Scala runtime library.

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 Scala minor 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 Kafka artifact, e.g. kafka_2.12 requires a Scala 2.12.x runtime library version.)

like image 131
Mike Allen Avatar answered Nov 15 '22 02:11

Mike Allen


Downloaded the scala libraries from http://scala-lang.org/download/ and added the scala-library.jar to the project, error resolved!

like image 2
mannedear Avatar answered Nov 15 '22 02:11

mannedear