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.
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.)
Downloaded the scala libraries from http://scala-lang.org/download/ and added the scala-library.jar to the project, error resolved!
Delete the unneccessary jar files and keep exact version jar file. It worked for me.
Related
We are upgrading our maven project to java 8 along with compatible tomcat.
The code is now being compiled with following errors:-
Caused by: java.lang.Error: Unresolved compilation problems:
The import org.apache.commons cannot be resolved
The import org.apache.commons cannot be resolved
The import org.apache.commons cannot be resolved
However it was working fine in Java 6 and Tomcat 7. We have checked that all the jars are included in WEB-INF/lib. It seems none of the apache-commons jar are getting recognized (not sure whats the correct term).
Just to check I moved apache-commons jars to tomcat/lib (never a solution obviously), but still same error.
Here's the Java and tomcat we are using :-
OpenJDK Runtime Environment (build 1.8.0_161-b14)
apache-tomcat-8.5.32
You need to update your project's POM.xml file to include dependencies for the Apache Commons libraries that you are using. If you do it correctly, the JARs will be downloaded from Maven Central into your ~/.m2 local repo, and added by Maven to the compile time build path. Then when Maven creates the WAR file for your project, it will include the JARs in the appropriate place in the WAR file ... ready for deployment to your Tomcat.
I recommend that you do some reading on Maven, the POM file and how Maven handles dependencies. The official "Maven Getting Started Guide" would be a good place to start.
It is unclear how you managed to get your project to build previously under Maven without the proper dependencies. I am guessing that you weren't using Maven before. Or maybe someone had been building by hand using IDE and ignoring Maven and the POM file entirely.
I recently migrated one of my personnal project from java 8 to java 10.
But then I ran into this warning which, as a warning hater, I had to fix.
Name of automatic module 'gson' is unstable, it is derived from the module's file name.
I checked the jar file I'm retrieving with maven and indeed, it's not a modular jar (there's no module-info.class in it).
So I checked GSON github and found out that there IS a module-info.java file for GSON.
So my questions are:
Why don't maven give me a modular jar? I find it very surprising considering modular jar can be used as regular jar when placed on the class path. Is it a maven thing?
What's the best way to retrieve a modular jar for GSON? (or even a JMOD file). Build the jar myself from github sources? Use an alternative to maven?
Additional informations:
IDE: Eclipse Photon Release (4.8.0)
JDK: 10.0.1
maven denpendency:
com.google.code.gson
gson
2.8.5
You're right, version 2.8.5 of Gson does contain a module-info but according to this issue it was in the wrong place. Although it's fixed now (1 month ago), a new release containing that fix has not yet been released.
I guess we'll have to wait.
I'm using Archlinux with both Thrift 0.9.3 and Apache installed. In my Netbeans project, when I import org.apache.thrift.*; I got "package org.apache.thrift does not exist". This answer didn't solved the problem because I got not /lib/java folder neither the other answer. Until the moment I couldn't find an answer on the internet. Thanks in advance.
You need the libthrift JAR file in order to use java code generated by the Thrift compiler.
If your project is set up to be able to use Maven repositories, you can add this artifact to your project:
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.9.3</version>
</dependency>
Alternatively you could just download the JAR file from Maven central and add it to your project:
http://central.maven.org/maven2/org/apache/thrift/libthrift/0.9.3/libthrift-0.9.3.jar
Also important to note is that the version of the JAR you use should match the version of the Thrift compiler that you use for code generation; so if you upgrade the Thrift compiler used for your project, you should upgrade the version of the JAR file as well.
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.
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.)
Downloaded the scala libraries from http://scala-lang.org/download/ and added the scala-library.jar to the project, error resolved!
Delete the unneccessary jar files and keep exact version jar file. It worked for me.
I'm trying to run Simple Hierarchy example of OWL API. I included owlapi-osgidistribution-4.0.2.jar and all libraries from its lib folder to the project class path. However I still have one unresolved import:
import static org.semanticweb.owlapi.search.EntitySearcher.getAnnotationObjects;
And one undefined method associated with that import:
for (OWLAnnotation anno : getAnnotationObjects(clazz, ontology)) {
anno.accept(le);
}
I see that EntitySearcher class is in the OWL API library. Have I missed something?
EntitySearcher is in the owlapi-api module, so should be found in your classpath.
That example is compiled routinely with each owlapi build, so it should not present any particular problem.
Note: I can't recall if the method you mention was added before or after 4.0.2 was released. It is possible that it was added for 4.1.0.
I went through the exact same instance of the problem yesterday, interesting coincidence.
The code that you're looking at is supposed to work with the latest version of the OWL API, namely 4.1.0-RC4. I've found hints to the problem browsing through the mailing list. Unfortunately the only available packaged version right now is the 4.0.2, and the latest version on the Maven repositories is 4.1.0-RC2, which didn't ship with the method used in the example.
The way I temporarily "solved" the problem was to use the Maven dependencies targeting version 4.1.0-RC2 and adding to the classpath the binary distribution for 4.1.0-RC4 built from the git repository (overriding the one for the older version resolved by Maven).
Assuming you know how to use Maven, this is the relevant entry of the POM file:
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-osgidistribution</artifactId>
<version>4.1.0-RC2</version>
</dependency>
To build the latest version of OWL API, just clone the git repository or download it as a zip file, extract and then run mvn clean install: the jar you want to add to your classpath should be present in the ./distribution/target/ directory.
You're also likely to get some warnings about the logger, if you want to fix that as well you need to get the tarball of slf4j with version matching the one that was resolved by Maven (from here, the version I used is 1.7.7), build it and then add slf4j-simple-#.#.#.jar to your classpath.
Hope this helps.