OWL API getAnnotationObjects method is undefined - java

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.

Related

new dependency not recognised by Maven

Using maven version 3.6.3 and JDK version "openjdk-17"
I've tried using Maven's dependencies so I could use the xstream library in my project. Following a guide I added com.thoughtworks.xstream to my pom.xml file:
I then tried to use xstream, but intellij couldn't resolve "XStream" even though it seems to work for JavaFX just fine. This code does not compile.
EDIT: I loaded a new project, where I used, what I believe to be, up to date versions. Maven 3.8.1, the latest intellij version, and everything else (JDK, openjfx) at version 17.0.2 yet when I try to use "XStream" in my project code (after reloading the maven project) it says "Cannot resolve symbol XStream"
Edit 2:
I added junit to the dependencies, it works. I add Gson to the dependencies. It doesn't work.
I figured out that in the "modules-info.java" file, "requires xstream" is needed. That is all
One of the following may solve your problem:
These are based on my previous experiences.
because may be auto import disabled. re Import maven project.(intellij: press Ctrl+Shift+A then actions - input "reload" find "Reload All Maven Projects").
in my experience, sometimes it does happen that the dependency is not fully received. remove xstream special version folder from .m2 (com->thoughtworks->xstream) and repeat step 1.
maybe repository not valid. check repository source in file settings.xml in .m2 (if exist) or replace to other source.
invalid cache and restart (intellij: file-> invalid caches/restart). This has solved my problem several times.
Your access to the site or repository may be closed. check network policy or use vpn (Poor probability)

Amazon PA API 5.0 migration - Cannot find Maven SDK dependency (public repository)

I need to do Amazon PA API Migration on March.
I'm trying to find a Maven public repository where is published the 'PA API 5.0 sdk'.
This is the official documentation : link
It says :
Download paapi5-java-sdk-and-samples archive and unzip it.
Open the project in any editor of your preference.
Add all jars present in dependencies folder to the build path.
It's not professional and not maintainable doing like this..
Also many of these jars are old versions (2016 like).
I've tried to contact AWS PA API support but I've got generic response (read documentation etc.)
Suggestions? Do you know Java unofficial libraries? Thanks
Same here. There is only an old maven sdk available. I cannot even import correctly the jar on intellij idea. The IDE is able to find alle the classes needed by the examples, but on building it says: "error: package com.amazon.paapi5.v1 does not exist". I added the jar with this procedure
I have the same problem and totally agree that it's not professional and not maintainable at all.
My current workaround is just to integrate manually the paapi5-java-sdk-1.0.0.jar and then figure out what other dependencies were missing, and which one I don't need (for example junit-4.12.jar does not make not much sense for me when I just want to use it in production).
You might already having some dependencies in place that you don't need to add. For example you might already have Jackson. So don't add this to your pom.
All other dependencies that you need, instead of using the jar files, just add the offical repo of them to your pom as usual with the same version as you find in the zip file. That way you have the least manual dependencies as currently possible and are sure all additional dependencies work fine with the Amazon SDK.
In my case I just had to add okhttp, okio, gson, gson-fire and threetenbp from the offical repo.
You can use mvn install to install downloaded jar into your local repository. See here
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

How to took up artifact version built with Gradle from sources

When using Maven, it's easy to look up latest version of SNAPSHOT artifact by going to parent's pom.xml:
https://github.com/apache/maven-compiler-plugin/blob/master/pom.xml#L33
But where do I look to get the same in Gradle?
For example I couldn't find any version in the sources here:
https://github.com/testcontainers/testcontainers-java
And if it's impossible, then why? How Gradle knows which version to build? Is this information external to the source code?
It depends on the project setup. The project you link to, according to their RELEASING.md, use the tag name for the version.
Create a new release on GitHub. The tag name is used as the version, so please keep the tag name plain (e.g. 1.2.3).
This is done by the Travis build script, .travis.yml, specifically the line
script: ./gradlew -Pversion=$TRAVIS_TAG release
Some projects will explicitly put a version=x.y.z in their gradle file, others will provide it explicitly on build (similar to the Travis script used).
The advantage of this setup is that the version is never in the script, and you can't get merge conflicts or accidental version overwrites on this.

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.
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.

Preferring the latest jar in a sea of dependencies (java)

I have a large Ivy project, and Ive noticed that my code, which run well in eclipse, cause a compile error when run in ant. I've narrowed the problem down to the following line :
FileUtils.write(...).
This line fails - during compilation --- the method is simply not found. Obviously, my code is dependant on apache's commons-io library. And its quite clear that the current commons-io has this method.
http://commons.apache.org/io/apidocs/org/apache/commons/io/FileUtils.html
So what gives ?
I am pretty sure this is related to my ivy.xml -> the eclipse compiler is luckily (or smartly) using the newest possible version of commons-io , whereas my ivy.xml is using an older version which lacks this method.
Most important of all to not here is that ant is clearly using a different version of this jar.
So - my question is :
1) How can I tell ant / ivy to preferentially compile my code with the latest versions of libraries i specify ? I'm assuming that some of the dependencies in my lib/ may depend on older versions of commons-io .....
Also :
2) In this context, any hints about what to worry about regarding the how the classloader deals with duplicates in a multi-jar-dependent project would also be helpful to me ...
Dependency Reporting
I would suggest that you first add the generation of an ivy dependency report into your build, using the report task.
An example of this task is included in the following answer:
What is the Ivy equivalent of Maven's versions:display-dependency-updates?
This will tell you what versions of what jars are being used. Normally, ivy will use the version you specify in the ivy.xml file, however, another module might depend on a more recent version. Ivy's default behaviour is to always favour the most recent version of a Maven module.
Retrieve the latest dependency
If you want ivy to always prefer the latest version of a particular library then declare the dependency as follows:
<dependency org="commons-io" name="commons-io" rev="latest.release"/>
Ivy has a feature called Fixed and Dynamic Revisions.
You can set the version/revision of any artifact to latest-status like
rev="latest.integration" --> for development released
rev="latest.release" --> for released versions
Ivy takes the version with the highest version(you have specified) and omits all libraries with lower versions, so that you only have one lib in the ivy classpath (have a look at the resolution report, run ant -v (verbose mode))., which avoids having duplicate jars with conflicting versions.
This might be worth checking out, maybe you just have an old version defined in one of your ivy files.
As to the second point:
The classloader takes the class, that happens to be first in the classpath(or the jar that is first in the classpath). So mixed versions of the same lib, could behave differently on any system, depending on how the classpath is constructed.

Categories

Resources