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.
Related
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 want to use the latest version of org.json in my Google App Engine project. My project uses GWT plugins, which provide their own, older version of org.json, so if I put my json.jar file into WEB-INF/lib it gets ignored. If I go to the Eclipse project's Properties > Java Build Path > Libraries to remove the GWT JDK jar the project won't compile. If I use the same properties tab to add my own json.jar to the list of libraries (via Add Jars...) it doesn't help.
Is there anything I can do, or am I stuck with the older version of org.json?
EDIT: I'm not using Maven.
GWT no longer uses org.json since 2.7, so all you'd have to do is use an up-to-date version.
That said, even with GWT 2.6.1 or older, you should be able to:
compile against your more recent version of org.json by putting it above the GWT JDK in Properties > Java Build Path > Order and Export
run with your more recent version of org.json by putting into WEB-INF/lib. If that's not enough, you'll maybe have to remove gwt-servlet-deps.jar (which contains org.json classes) and replace it with validation-api-1.0.0.GA.jar. That however will only with GWT 2.6; with an even-older version you're out of luck (but 2.6.0 is almost 2 years old already, and 2.5.0 3 years old, that's an eternity at web scale)
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.
I've used a 17 version of Guava for my library project and extracted it into the jar. Other project uses my library but it also has a much older version of Guava. When I try to run application, it ignores new Guava and causes errors like
java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.maximumSize(J)Lcom/google/common/cache/CacheBuilder;
How to force my project to use a new Guava and application to use an old?
I am assuming that your project and applications are distinct entities.Also, by Project I assume that you are referring to an Eclipse/IntelliJ/Netbeans project
You would need to set the correct classpaths for the Project and your application separately.
If you are using the IDE to debug your project, your project would need to include the new JAR that you have downloaded. Each IDE has it's own mechanism for adding dependencies to the Project's classpath and hence you would want to refer to the documentation related to that IDE.
For your application you can launch it as java MyApp -cp "path to the old JAR". If you are packaging your application as a JAR, make sure you are packaging the older version of Guava.
Hope this helps.
Edit based on the discussion with the owner of the question
The query here is similar to this SO query. The right way to hence resolve this issue would be either install a Custom ClassLoader or use OSGi
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.