'Create reasoner does not work on Tomcat deployment
Context: I am working on a Java Spring Boot web application that manipulates OWL and RDF data for various tasks (ontology loading, consistency checking, inconsistency explanations generations and querying thru SPARQL). I am using OWLAPI, HermiT, OWLExplanation and ONTAPI libraries (dependencies below). When I run the application using the tomcat embedded in Intellij, everything works fine.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.12.RELEASE</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-apibinding</artifactId>
<version>5.1.20</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.3.8.510</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlexplanation</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.github.owlcs</groupId>
<artifactId>ontapi</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
Problem: When I deploy the webapp in a Tomcat9 instance, it throws an exception when trying to create a reasoner from the reasoner factory (last line of the code snippet below). Probably, it is a dependency problem. But I don't where to start looking, because all the libraries cited above are being deployed together with the webapp. Code snippet, error message and stacktrace follows.
Code snippet:
import com.github.owlcs.ontapi.OntManagers;
import com.github.owlcs.ontapi.Ontology;
import com.github.owlcs.ontapi.OntologyManager;
import org.semanticweb.HermiT.Configuration;
import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owlapi.io.StringDocumentSource;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.rdf.turtle.parser.TurtleOntologyParser;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
Ontology ontology;
// load string source into ontology manager
StringDocumentSource docSource = new StringDocumentSource(source);
OntologyManager manager = OntManagers.createManager();
try {
ontology = manager.loadOntologyFromOntologyDocument(docSource);
} catch (OWLOntologyCreationException e) {
return null;
} catch (Throwable t) {
throw new Throwable("OWL/XML syntax parsing problem.");
}
// start reasoner with configuration for explanations
Configuration configuration = new Configuration();
configuration.throwInconsistentOntologyException = false;
OWLReasonerFactory reasonerFactory = new ReasonerFactory();
OWLReasoner reasoner;
reasoner = reasonerFactory.createReasoner(ontology, configuration);
Error message:
Unable to create injector, see the following errors:
1) No implementation for java.util.Set<org.semanticweb.owlapi.io.OWLParserFactory> was bound.
while locating java.util.Set<org.semanticweb.owlapi.io.OWLParserFactory>
for the 1st parameter of uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyParsers(OWLOntologyManagerImpl.java:1456)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyParsers(OWLOntologyManagerImpl.java:1456)
at uk.ac.manchester.cs.owl.owlapi.OWLAPIImplModule.configure(Unknown Source)
2) No implementation for java.util.Set<org.semanticweb.owlapi.model.OWLOntologyIRIMapper> was bound.
while locating java.util.Set<org.semanticweb.owlapi.model.OWLOntologyIRIMapper>
for the 1st parameter of uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setIRIMappers(OWLOntologyManagerImpl.java:1407)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setIRIMappers(OWLOntologyManagerImpl.java:1407)
at uk.ac.manchester.cs.owl.owlapi.OWLAPIImplModule.configure(Unknown Source)
3) No implementation for java.util.Set<org.semanticweb.owlapi.model.OWLStorerFactory> was bound.
while locating java.util.Set<org.semanticweb.owlapi.model.OWLStorerFactory>
for the 1st parameter of uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyStorers(OWLOntologyManagerImpl.java:1394)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyStorers(OWLOntologyManagerImpl.java:1394)
at uk.ac.manchester.cs.owl.owlapi.OWLAPIImplModule.configure(Unknown Source)
4) An exception was caught and reported. Message: Injection failed for interface org.semanticweb.owlapi.model.OWLOntologyFactory
at org.semanticweb.owlapi.OWLAPIServiceLoaderModule.configure(Unknown Source)
Stacktrace:
com.google.inject.internal.MessageProcessor.visit An exception was caught and reported. Message: java.lang.NoSuchMethodException: uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.<init>()
org.semanticweb.owlapi.model.OWLRuntimeException: Injection failed for interface org.semanticweb.owlapi.model.OWLOntologyFactory
at org.semanticweb.owlapi.OWLAPIServiceLoaderModule.loadInstancesFromServiceLoader(OWLAPIServiceLoaderModule.java:62)
at org.semanticweb.owlapi.OWLAPIServiceLoaderModule.configure(OWLAPIServiceLoaderModule.java:49)
at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
at com.google.inject.spi.Elements.getElements(Elements.java:110)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:99)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at org.semanticweb.owlapi.apibinding.OWLManager.createInjector(OWLManager.java:104)
at org.semanticweb.owlapi.apibinding.OWLManager.createOWLOntologyManager(OWLManager.java:44)
at org.semanticweb.HermiT.structural.ObjectPropertyInclusionManager.buildIndividualAutomata(ObjectPropertyInclusionManager.java:721)
at org.semanticweb.HermiT.structural.ObjectPropertyInclusionManager.createAutomata(ObjectPropertyInclusionManager.java:192)
at org.semanticweb.HermiT.structural.ObjectPropertyInclusionManager.<init>(ObjectPropertyInclusionManager.java:52)
at org.semanticweb.HermiT.structural.OWLClausification.preprocessAndClausify(OWLClausification.java:83)
at org.semanticweb.HermiT.Reasoner.loadOntology(Reasoner.java:210)
at org.semanticweb.HermiT.Reasoner.<init>(Reasoner.java:201)
at org.semanticweb.HermiT.Reasoner.<init>(Reasoner.java:175)
at org.semanticweb.HermiT.ReasonerFactory.createHermiTOWLReasoner(ReasonerFactory.java:51)
at org.semanticweb.HermiT.ReasonerFactory.createReasoner(ReasonerFactory.java:19)
at ufpe.dare.arcade.arcadewebontapi.OntologyController.loadOntology(OntologyController.java:130)
at ufpe.dare.arcade.arcadewebontapi.ArcadeWebOntAPIApplication.uploadOntology(ArcadeWebOntAPIApplication.java:78)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:126)
at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:64)
at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:101)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:375)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1639)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.util.ServiceConfigurationError: org.semanticweb.owlapi.model.OWLOntologyFactory: uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl Unable to get public no-arg constructor
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:673)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1233)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at java.base/java.lang.Iterable.forEach(Iterable.java:74)
at org.semanticweb.owlapi.OWLAPIServiceLoaderModule.load(OWLAPIServiceLoaderModule.java:86)
at org.semanticweb.owlapi.OWLAPIServiceLoaderModule.loadInstancesFromServiceLoader(OWLAPIServiceLoaderModule.java:60)
... 80 more
Caused by: java.lang.NoSuchMethodException: uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3349)
at java.base/java.lang.Class.getConstructor(Class.java:2151)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:660)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:657)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:668)
... 87 more
I'll appreciate any help.
Solution 1:[1]
The error stack trace refers to Guice issues, but Guice has been removed from OWLAPI 5.1.6 and newer.
Your pom shows OWLAPI 5.1.20, so this implies there are multiple OWLAPI versions in the Tomcat classpath for your deployed app.
Depending on your IDE, you might be able to see what versions of OWLAPI are referenced and exclude them. Another approach would be to check the war file you've built for Tomcat and see what jars appear in it. I expect OWLAPI jars marked 5.1.20 will appear alongside OWLAPI jars with the same name and an earlier version number.
This might work as expected on your embedded Tomcat just because of classpath order - if the correct OWLAPI files are found before the incorrect ones, everything would work fine.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ignazio |