简体   繁体   English

球衣+ OWL API 3

[英]Jersey + OWL API 3

Good morning people. 大家早上好。

I am trying to load an ontology from a Restfull service using Jersey. 我正在尝试使用Jersey从Restfull服务加载本体。 However, my application throws exception in the following line: 但是,我的应用程序在以下行中引发异常:

OWLOntologyManager manager OWLManager.createOWLOntologyManager = ();

I thank the help of all. 我感谢所有人的帮助。

Error log: 错误日志:

javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class org.semanticweb.owlapi.apibinding.OWLManager
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

My web.xml: 我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>SemanticMDX</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

My Service: 我的服务:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/semantichelper")
public class WS_SemanticMDX {
    @GET
    @Produces("application/xml")
    public String convertCtoF() {
        AssistenteSemantico moduloSemantico = new AssistenteSemantico();
        moduloSemantico.loadOWLOntology();

    return "";
    }
}

Method to load ontology: 加载本体的方法:

public class AssistenteSemantico {
public static final IRI iri = IRI.create(
        "myIRI/NovaOntologiaDeFeriados.owl");

public OWLOntology loadOwlOntology(){
    OWLOntology owlOntologyRedirect = null;
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 

    manager.addIRIMapper(new SimpleIRIMapper(
            iri,
            IRI.create(new File(myPath/OntologiaDeFeriados-v4.owl"))));
    try {
        owlOntologyRedirect = manager.loadOntology(iri);
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
    }

    return owlOntologyRedirect;
}

pom.xml pom.xml

<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>SemanticMDX</groupId>
<artifactId>SemanticMDX</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>owlapi-distribution</artifactId>
        <version>3.5.2</version>
    </dependency>
    <dependency>
        <groupId>com.github.ansell.pellet</groupId>
        <artifactId>pellet-owlapiv3</artifactId>
        <version>2.3.3</version>
    </dependency>

    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20140107</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19</version>
    </dependency>
</dependencies>

error after adding the jar OWL API both in WEB-INF / lib as in diterório lib tomcat: 在WEB-INF / lib中都添加jar OWL API后出现错误,就像在diteróriolib tomcat中一样:

com.google.inject.CreationException: Unable to create injector, see the following errors:

1) No implementation for java.util.Set was bound. 1)没有绑定java.util.Set的实现。 while locating java.util.Set for parameter 0 at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyStorers(OWLOntologyManagerImpl.java:1333) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyStorers(OWLOntologyManagerImpl.java:1333) at uk.ac.manchester.cs.owl.owlapi.OWLAPIImplModule.configure(OWLAPIImplModule.java:61) 在uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyStorers(uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.setOntologyStorers(OWLOntologyManagerImpl.java:1333)处找到参数0的java.util.Set时OWLOntologyManagerImpl.java:1333)位于uk.ac.manchester.cs.owl.owlapi.OWLAPIImplModule.configure(OWLAPIImplModule.java:61)

2) An exception was caught and reported. 2)捕获并报告了异常。 Message: org.semanticweb.owlapi.oboformat.OBOFormatOWLAPIParserFactory cannot be cast to javax.inject.Provider at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138) 消息:org.semanticweb.owlapi.oboformat.OBOFormatOWLAPIParserFactory无法在com.google.inject.internal.InjectorShell $ Builder.build(InjectorShell.build(InjectorShell.java:138)处转换为javax.inject.Provider

2 errors com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:466) com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155) com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107) com.google.inject.Guice.createInjector(Guice.java:96) com.google.inject.Guice.createInjector(Guice.java:73) com.google.inject.Guice.createInjector(Guice.java:62) org.semanticweb.owlapi.apibinding.OWLManager.createInjector(OWLManager.java:89) org.semanticweb.owlapi.apibinding.OWLManager.instatiateOWLOntologyManager(OWLManager.java:97) org.semanticweb.owlapi.apibinding.OWLManager.createOWLOntologyManager(OWLManager.java:58) AssistenteSemantico.carregarOwlOntology(AssistenteSemantico.java:35) AssistenteSemantico.inferirDiasParteDeIntervaloPorNomeindividuo(AssistenteSemantico.java:112) WS_SemanticMDX.convertCtoF(WS_SemanticMDX.java:17) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.ref 2个错误com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:466)com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155)com.google.inject.internal.InternalInjectorCreator.build( InternalInjectorCreator.java:107)com.google.inject.Guice.createInjector(Guice.java:96)com.google.inject.Guice.createInjector(Guice.java:73)com.google.inject.Guice.createInjector(Guice。 java:62)org.semanticweb.owlapi.apibinding.OWLManager.createInjector(OWLManager.java:89)org.semanticweb.owlapi.apibinding.OWLManager.instatiateOWLOntologyManager(OWLManager.java:97)org.semanticweb.owlapi.apibinding.OWLManager。 createOWLOntologyManager(OWLManager.java:58)AssistenteSemantico.carregarOwlOntology(AssistenteSemantico.java:35)AssistenteSemantico.inferirDiasParteDeIntervaloPorNomeindividuo(AssistenteSemantico.java:112)WS_SemanticMDX.MethodI。 .ref lect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) com.sun.jersey.server.impl.application.WebApp lect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:606)com.sun.jersey.spi。 container.JavaMethodInvokerFactory $ 1.invoke(JavaMethodInvokerFactory.java:60)com.sun.jersey.server.impl.model.method.dispatch.Abs​​tractResourceMethodDispatchProvider $ TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)com.sun.jersey.server.impl .model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)com.sun.jersey.server.impl .uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)com.sun.jersey.server.impl.uri .rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)com.sun.jersey.server.impl.application.WebApp licationImpl._handleRequest(WebApplicationImpl.java:1542) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause licationImpl._handleRequest(WebApplicationImpl.java:1542)com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl。 java:1419)com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)com。 sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)javax.servlet.http.HttpServlet。 service(HttpServlet.java:729)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)根本原因

java.lang.ClassCastException: org.semanticweb.owlapi.oboformat.OBOFormatOWLAPIParserFactory cannot be cast to javax.inject.Provider org.semanticweb.owlapi.OWLAPIServiceLoaderModule.loadFactories(OWLAPIServiceLoaderModule.java:109) org.semanticweb.owlapi.OWLAPIServiceLoaderModule.configure(OWLAPIServiceLoaderModule.java:59) com.google.inject.AbstractModule.configure(AbstractModule.java:62) com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340) com.google.inject.spi.Elements.getElements(Elements.java:110) com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138) com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104) com.google.inject.Guice.createInjector(Guice.java:96) com.google.inject.Guice.createInjector(Guice.java:73) com.google.inject.Guice.createInjector(Guice.java:62) org.semanticweb.owlapi.apibinding.OWLManager.createInjector(OWLManager.java:89) org.semanticweb.owlapi.apibinding.OWLManager.instatiateOWLOn java.lang.ClassCastException:org.semanticweb.owlapi.oboformat.OBOFormatOWLAPIParserFactory无法转换为javax.inject.Provider org.semanticweb.owlapi.OWLAPIServiceLoaderModule.loadFactories(OWLAPIServiceLoaderModule.java:109)org.semanticweb.owlapi.OWAPI。 OWLAPIServiceLoaderModule.java:59)com.google.inject.AbstractModule.configure(AbstractModule.java:62)com.google.inject.spi.Elements $ RecordingBinder.install(Elements.java:340)com.google.inject.spi。 Elements.getElements(Elements.java:110)com.google.inject.internal.InjectorShell $ Builder.build(InjectorShell.java:138)com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)com。 google.inject.Guice.createInjector(Guice.java:96)com.google.inject.Guice.createInjector(Guice.java:73)com.google.inject.Guice.createInjector(Guice.java:62)org.semanticweb。 owlapi.apibinding.OWLManager.createInjector(OWLManager.java:89)org.semanticweb.owlapi.apibinding.OWLManager.instatiateOWLOn tologyManager(OWLManager.java:97) org.semanticweb.owlapi.apibinding.OWLManager.createOWLOntologyManager(OWLManager.java:58) AssistenteSemantico.carregarOwlOntology(AssistenteSemantico.java:35) AssistenteSemantico.inferirDiasParteDeIntervaloPorNomeindividuo(AssistenteSemantico.java:112) WS_SemanticMDX.convertCtoF(WS_SemanticMDX.java:17) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) com.s tologyManager(OWLManager.java:97)org.semanticweb.owlapi.apibinding.OWLManager.createOWLOntologyManager(OWLManager.java:58)AssistenteSemantico.carregarOwlOntology(AssistenteSemantico.java:35)AssistenteSemantico.inferirDiasParteDemanvalSentFantSentEmanSentFant(enterSentCentManentent。 WS_SemanticMDX.java:17)sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesslectImpl.java:43)。 .Method.invoke(Method.java:606)com.sun.jersey.spi.container.JavaMethodInvokerFactory $ 1.invoke(JavaMethodInvokerFactory.java:60)com.sun.jersey.server.impl.model.method.dispatch.Abs​​tractResourceMethodDispatchProvider $ TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)com.s un.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) com.sun.jersey.spi.container.servlet.ServletContainer.servic un.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)com.sun。 jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)com.sun.jersey。 server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)com.sun.jersey.server.impl.application。 WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent。 java:409)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)com.sun.jersey.spi.container.servlet.ServletContainer.servic e(ServletContainer.java:733) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) e(ServletContainer.java:733)javax.servlet.http.HttpServlet.service(HttpServlet.java:729)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Your pom file looks correct, but the error seems to suggest the OWLAPI jars are not being included correctly in your web application. 您的pom文件看起来正确,但是错误似乎表明OWLAPI jar未正确包含在您的Web应用程序中。 Check the content of WEB-INF/lib , the owlapi-distribution jar should be there. 检查WEB-INF/lib的内容, owlapi-distribution jar应该在那里。

Edit: The new error cannot happen with OWLAPI 3 - it refers to code that's only available in OWLAPI 4. I believe you now have multiple versions in your classpath. 编辑:OWLAPI 3不会发生新错误-它引用的代码仅在OWLAPI 4中可用。我相信您的类路径中现在有多个版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM