Issue
I am trying to call an OWL API java program through terminal and it crashes, while the exact same code is running ok when I run it in IntelliJ.
The exception that rises in my main code is this:
Exception in thread "main" java.lang.NoSuchMethodError: 'boolean org.semanticweb.owlapi.io.RDFResource.idRequiredForIndividualOrAxiom()'
at org.semanticweb.owlapi.rdf.rdfxml.renderer.RDFXMLRenderer.render(RDFXMLRenderer.java:204)
at org.semanticweb.owlapi.rdf.RDFRendererBase.render(RDFRendererBase.java:448)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderOntologyHeader(RDFRendererBase.java:441)
at org.semanticweb.owlapi.rdf.RDFRendererBase.render(RDFRendererBase.java:247)
at org.semanticweb.owlapi.rdf.rdfxml.renderer.RDFXMLStorer.storeOntology(RDFXMLStorer.java:51)
at org.semanticweb.owlapi.util.AbstractOWLStorer.storeOntology(AbstractOWLStorer.java:142)
at org.semanticweb.owlapi.util.AbstractOWLStorer.storeOntology(AbstractOWLStorer.java:106)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:1347)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:1333)
at com.stelios.JavaExplanations.main(JavaExplanations.java:112)
It seems as if calling idRequiredForIndividualOrAxiom()
on an RDFResource
object doesn't find the method that is inherited by RDFNode
class, but I have no clue why.
In order to post here, I kept only the saveOntology
call in a minimal example and the exception that is thrown is the same with extra steps:
Exception in thread "main" java.lang.NoSuchMethodError: 'boolean org.semanticweb.owlapi.io.RDFResource.idRequiredForIndividualOrAxiom()'
at org.semanticweb.owlapi.rdf.rdfxml.renderer.RDFXMLRenderer.render(RDFXMLRenderer.java:204)
at org.semanticweb.owlapi.rdf.rdfxml.renderer.RDFXMLRenderer.render(RDFXMLRenderer.java:249)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderEntity(RDFRendererBase.java:298)
at org.semanticweb.owlapi.rdf.RDFRendererBase.render(RDFRendererBase.java:292)
at org.semanticweb.owlapi.rdf.RDFRendererBase.lambda$renderEntities$6(RDFRendererBase.java:285)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:1033)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderEntities(RDFRendererBase.java:285)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderInOntologySignatureEntities(RDFRendererBase.java:269)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderOntologyComponents(RDFRendererBase.java:253)
at org.semanticweb.owlapi.rdf.RDFRendererBase.render(RDFRendererBase.java:248)
at org.semanticweb.owlapi.rdf.rdfxml.renderer.RDFXMLStorer.storeOntology(RDFXMLStorer.java:51)
at org.semanticweb.owlapi.util.AbstractOWLStorer.storeOntology(AbstractOWLStorer.java:142)
at org.semanticweb.owlapi.util.AbstractOWLStorer.storeOntology(AbstractOWLStorer.java:106)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:1347)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:1333)
at com.stelios.JavaExplanations.main(JavaExplanations.java:47)
In both my original code and the minimal example I call java with: java -cp /home/stelios/java_explanations/target/java_explanations-1.0-SNAPSHOT-jar-with-dependencies.jar com.stelios.JavaExplanations
Here is the minimal example that repeats this behavior for me. This is the Java code:
package com.stelios;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.*;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.*;
import org.semanticweb.owlapi.model.*;
public class JavaExplanations {
public static void main(String[] args) throws OWLOntologyCreationException, FileNotFoundException, OWLOntologyStorageException {
String ontology1 = "/home/stelios/Desktop/huiyfgds/ONTO_ASRTD_hz162pai";
String ontology2 = "/home/stelios/Desktop/huiyfgds/ONTO_INFRD_hz162pai";
OWLOntologyManager ontology_manager = OWLManager.createOWLOntologyManager();
OWLOntology asserted_ontology = ontology_manager.loadOntologyFromOntologyDocument(new File(ontology1));
ontology_manager.saveOntology(asserted_ontology, new StreamDocumentTarget(new FileOutputStream(ontology2)));
}
}
This is the pom.xml
in IntelliJ:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stelios.expl</groupId>
<artifactId>java_explanations</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/owlexplanation -->
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlexplanation</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.4.5.519</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.32</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
</build>
</project>
I think that most probably it is some dependency/version error but I don't see how this can be. I package everything I need in the jar file I give as classpath, defining the wanted versions in pom.xml, and in this jar I can find only one org/semanticweb/owlapi/io/RDFResource.class file.
Reading this and this I thought about having 2 different versions of OWL API, as I had another .jar with OWL API version 3.4.9 in it, in the directory tree. I moved the file and rebuilt the maven package just to be sure, and (as expected) no change.
Other than the saveOntology() call, my original program is working as intended.
The only thing out of the ordinary is that IntelliJ is giving me a Plugin 'maven-assembly-plugin:' not found
problem, which I haven't managed to solve in any way, and have been ignoring as it hasn't been an issue in any of the operations I have needed. (If you know how to solve it of course, give me suggestions, but my main problem is the earlier mentioned exception).
EDIT Here is the mvn dependency:tree
output.
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.stelios.expl:java_explanations >-----------------
[INFO] Building java_explanations 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ java_explanations ---
[INFO] com.stelios.expl:java_explanations:jar:1.0-SNAPSHOT
[INFO] +- net.sourceforge.owlapi:owlexplanation:jar:5.0.0:compile
[INFO] | +- net.sourceforge.owlapi:owlapi-api:jar:5.1.19:compile (version selected from constraint [5.0.0,5.9.9])
[INFO] | | \- javax.inject:javax.inject:jar:1:compile
[INFO] | +- net.sourceforge.owlapi:owlapi-tools:jar:5.1.19:compile (version selected from constraint [5.0.0,5.9.9])
[INFO] | \- net.sourceforge.owlapi:telemetry:jar:5.0.0:compile
[INFO] | \- net.sourceforge.owlapi:owlapi-parsers:jar:5.1.19:compile (version selected from constraint [5.0.0,5.9.9])
[INFO] +- net.sourceforge.owlapi:owlapi-distribution:jar:5.1.9:compile
[INFO] | +- net.sourceforge.owlapi:owlapi-compatibility:jar:5.1.9:compile
[INFO] | | \- net.sourceforge.owlapi:owlapi-apibinding:jar:5.1.9:compile
[INFO] | | +- net.sourceforge.owlapi:owlapi-impl:jar:5.1.9:compile
[INFO] | | +- net.sourceforge.owlapi:owlapi-oboformat:jar:5.1.9:compile
[INFO] | | \- net.sourceforge.owlapi:owlapi-rio:jar:5.1.9:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.9.7:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.7:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.7:compile
[INFO] | +- org.apache.commons:commons-rdf-api:jar:0.5.0:compile
[INFO] | +- org.tukaani:xz:jar:1.6:compile
[INFO] | +- org.slf4j:jcl-over-slf4j:jar:1.7.22:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-model:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-api:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-languages:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-datatypes:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-binary:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-n3:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-nquads:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-ntriples:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-rdfjson:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-jsonld:jar:2.3.2:compile
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] | | | \- org.apache.httpcomponents:httpcore:jar:4.4.4:compile
[INFO] | | \- org.apache.httpcomponents:httpclient-cache:jar:4.5.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-rdfxml:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-trix:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-turtle:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-rio-trig:jar:2.3.2:compile
[INFO] | +- org.eclipse.rdf4j:rdf4j-util:jar:2.3.2:compile
[INFO] | +- com.github.jsonld-java:jsonld-java:jar:0.12.0:compile
[INFO] | | +- org.apache.httpcomponents:httpclient-osgi:jar:4.5.5:compile
[INFO] | | | +- org.apache.httpcomponents:httpmime:jar:4.5.5:compile
[INFO] | | | \- org.apache.httpcomponents:fluent-hc:jar:4.5.5:compile
[INFO] | | \- org.apache.httpcomponents:httpcore-osgi:jar:4.4.9:compile
[INFO] | | \- org.apache.httpcomponents:httpcore-nio:jar:4.4.9:compile
[INFO] | +- com.github.vsonnier:hppcrt:jar:0.7.5:compile
[INFO] | +- com.github.ben-manes.caffeine:caffeine:jar:2.6.1:compile
[INFO] | +- com.google.guava:guava:jar:22.0:compile (version selected from constraint [18.0,22.0])
[INFO] | | +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO] | | +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] | | \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile (version selected from constraint [2.0.0,4))
[INFO] | \- commons-io:commons-io:jar:2.5:compile
[INFO] +- net.sourceforge.owlapi:org.semanticweb.hermit:jar:1.4.5.519:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] | +- org.apache.ws.commons.axiom:axiom-api:jar:1.2.14:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-activation_1.1_spec:jar:1.1:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
[INFO] | | +- jaxen:jaxen:jar:1.1.4:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:compile
[INFO] | | \- org.apache.james:apache-mime4j-core:jar:0.7.2:compile
[INFO] | +- org.apache.ws.commons.axiom:axiom-c14n:jar:1.2.14:compile
[INFO] | +- org.apache.ws.commons.axiom:axiom-impl:jar:1.2.14:compile
[INFO] | | \- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.4:compile
[INFO] | | \- org.codehaus.woodstox:stax2-api:jar:3.1.1:compile
[INFO] | +- org.apache.ws.commons.axiom:axiom-dom:jar:1.2.14:compile
[INFO] | +- dk.brics.automaton:automaton:jar:1.11-8:compile
[INFO] | +- gnu.getopt:java-getopt:jar:1.0.13:compile
[INFO] | \- net.sf.trove4j:trove4j:jar:3.0.3:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.22:compile
[INFO] +- org.slf4j:slf4j-nop:jar:1.7.32:compile
[INFO] \- org.apache.maven.plugins:maven-assembly-plugin:maven-plugin:3.3.0:compile
[INFO] +- org.apache.maven:maven-plugin-api:jar:3.0:compile
[INFO] | \- org.sonatype.sisu:sisu-inject-plexus:jar:1.4.2:compile
[INFO] | \- org.sonatype.sisu:sisu-inject-bean:jar:1.4.2:compile
[INFO] | \- org.sonatype.sisu:sisu-guice:jar:noaop:2.1.7:compile
[INFO] +- org.apache.maven:maven-core:jar:3.0:compile
[INFO] | +- org.apache.maven:maven-settings:jar:3.0:compile
[INFO] | +- org.apache.maven:maven-settings-builder:jar:3.0:compile
[INFO] | +- org.apache.maven:maven-repository-metadata:jar:3.0:compile
[INFO] | +- org.apache.maven:maven-model-builder:jar:3.0:compile
[INFO] | +- org.apache.maven:maven-aether-provider:jar:3.0:runtime
[INFO] | +- org.sonatype.aether:aether-impl:jar:1.7:compile
[INFO] | | \- org.sonatype.aether:aether-spi:jar:1.7:compile
[INFO] | +- org.sonatype.aether:aether-api:jar:1.7:compile
[INFO] | +- org.sonatype.aether:aether-util:jar:1.7:compile
[INFO] | +- org.codehaus.plexus:plexus-classworlds:jar:2.2.3:compile
[INFO] | +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO] | \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[INFO] | \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[INFO] +- org.apache.maven:maven-artifact:jar:3.0:compile
[INFO] +- org.apache.maven:maven-model:jar:3.0:compile
[INFO] +- org.apache.maven.shared:maven-common-artifact-filters:jar:3.1.0:compile
[INFO] | \- org.apache.maven.shared:maven-shared-utils:jar:3.1.0:compile
[INFO] +- org.apache.maven.shared:maven-artifact-transfer:jar:0.11.0:compile
[INFO] +- org.codehaus.plexus:plexus-interpolation:jar:1.25:compile
[INFO] +- org.codehaus.plexus:plexus-archiver:jar:4.2.1:compile
[INFO] | +- org.apache.commons:commons-compress:jar:1.19:compile
[INFO] | \- org.iq80.snappy:snappy:jar:0.4:compile
[INFO] +- org.apache.maven.shared:file-management:jar:3.0.0:compile
[INFO] +- org.apache.maven.shared:maven-shared-io:jar:3.0.0:compile
[INFO] | +- org.apache.maven:maven-compat:jar:3.0:compile
[INFO] | \- org.apache.maven.wagon:wagon-provider-api:jar:2.10:compile
[INFO] +- org.apache.maven.shared:maven-filtering:jar:3.1.1:compile
[INFO] | \- org.sonatype.plexus:plexus-build-api:jar:0.0.7:compile
[INFO] +- org.codehaus.plexus:plexus-io:jar:3.2.0:compile
[INFO] +- org.apache.maven:maven-archiver:jar:3.5.0:compile
[INFO] +- org.codehaus.plexus:plexus-utils:jar:3.3.0:compile
[INFO] \- commons-codec:commons-codec:jar:1.6:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.339 s
[INFO] Finished at: 2022-01-27T13:06:01+02:00
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0
Solution
As can be seen in the comments of the post, my problem is fixed, so I thought I'd collect a closing answer here to not leave the post pending.
The actual solution: As explained here nicely by @UninformedUser, the issue was that I had conflicting maven package versions in my dependencies. Bringing everything in sync with each other solved the issue.
Incidental solution: As I wrote in the comments above, specifically defining <version>3.3.0</version>
for the maven-assembly-plugin
happened to solve the issue. But this was only chance, as explained here by @Ignazio, just because the order of "assembling" things changed, overwriting the conflicting package.
Huge thanks to both for the help.
Answered By - SteliosKts
Answer Checked By - Marie Seifert (JavaFixing Admin)