在执行OWL API时出错

我正试图执行以下代码。

import java.io.File;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class Snippet {
public static void main(String[] args) throws OWLOntologyCreationException {
    File file = new File(
            "file:///c/Users/DTN/Desktop/Final SubmissionFilteringMechanism_Ontology.owl");
    OWLOntologyManager m = OWLManager.createOWLOntologyManager();
    OWLDataFactory f = OWLManager.getOWLDataFactory();
    OWLOntology o;
    o = m.loadOntologyFromOntologyDocument(file);
    OWLClass clsA = f.getOWLClass(IRI.create("urn:test#ClassA"));
    OWLClass clsB = f.getOWLClass(IRI.create("urn:test#ClassB"));
    OWLAxiom ax1 = f.getOWLSubClassOfAxiom(clsA, clsB);
    AddAxiom addAxiom1 = new AddAxiom(o, ax1);
    m.applyChange(addAxiom1);
    for (OWLClass cls : o.getClassesInSignature()) {
        System.out.println(cls.getIRI());
    }
    m.removeOntology(o);
}
}

它正在产生以下错误。

异常在线程“main”java.lang.NoClassDefFoundError:com / google / inject / Provider在java.lang.ClassLoader.defineClass1(本地方法)在java.lang.ClassLoader.defineClass(未知源)在java.security.SecureClassLoader。 java.net.URLClassLoader.access上的java.net.URLClassLoader.defineClass(未知源)上的defineClass(Unknown Source)java.net.URLClassLoader上的$ 100(未知源)在java.net.URLClassLoader上的$ 1.run(未知源)$ 1 .run(Unknown Source)at java.net.URLClassLoader.findClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)at sun.misc.Launcher $ AppClassLoader(Unknown Source)at java.security.AccessController.doPrivileged(Native Method) .loadClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)at java.lang.ClassLoader.defineClass1(Native Method)at java.lang.ClassLoader.defineClass(Unknown Source)at java.security.SecureClassLoader.defineClass (Unknown Source)at java.net.URLClassLoader.defineClass(Unknown Source)at java.net.URLClassLoader.access $ 1 00(未知源)在java.net.URLClassLoader $ 1.run(未知源)在java.net.URLClassLoader $ 1.run(未知源)在java.security.AccessController.doPrivileged(本地方法)在java.net.URLClassLoader。在test.main(test。)上,在java.lang.ClassLoader.loadClass(Unknown Source)处的sun.misc.Launcher $ AppClassLoader.loadClass(Unknown Source)处的java.lang.ClassLoader.loadClass(Unknown Source)处的findClass(Unknown Source)。 java:18)导致:java.lang.ClassNotFoundException:com.google.inject.Provider在java.net.URLClassLoader.findClass(未知源)在java.lang.ClassLoader.loadClass(未知源)在sun.misc.Launcher $ AppClassLoader.loadClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)... 25更多

请一些身体帮助我。 提前致谢。


你的班级路径中包括了什么罐子?

它看起来像你缺少一些谷歌guice依赖。 我建议使用一些依赖管理工具,比如maven或gradle

例如,我通过使用Maven依赖来解决这个问题

net.sourceforge.owlapi:owlapi-osgidistribution:4.0.2

在一个以你的Snippet类作为主类的Maven项目中。

<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>fake</groupId>
<artifactId>fake</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
  <dependency>
    <groupId>net.sourceforge.owlapi</groupId>
    <artifactId>owlapi-osgidistribution</artifactId>
    <version>4.0.2</version>
  </dependency>
</dependencies>

如果你想在不使用依赖关系管理器的情况下运行它,请确保在你的类路径中包含以下jar包(以下列表是使用maven依赖关系树命令获得的)

[INFO] - net.sourceforge.owlapi:owlapi-osgidistribution:jar:4.0.2:compile
[INFO]    +- org.openrdf.sesame:sesame-model:jar:2.7.12:compile
[INFO]    |  - org.openrdf.sesame:sesame-util:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-api:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-languages:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-datatypes:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-binary:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-n3:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-nquads:jar:2.7.12:compile
[INFO]    |  - commons-io:commons-io:jar:2.4:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-ntriples:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-rdfjson:jar:2.7.12:compile
[INFO]    |  - com.fasterxml.jackson.core:jackson-core:jar:2.2.1:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-rdfxml:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-trix:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-turtle:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-trig:jar:2.7.12:compile
[INFO]    +- com.github.jsonld-java:jsonld-java-sesame:jar:0.5.0:compile
[INFO]    |  - com.github.jsonld-java:jsonld-java:jar:0.5.0:compile
[INFO]    |     +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile
[INFO]    |     |  - com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
[INFO]    |     +- org.apache.httpcomponents:httpclient-cache:jar:4.2.5:compile
[INFO]    |     +- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[INFO]    |     |  +- org.apache.httpcomponents:httpcore:jar:4.2.4:compile
[INFO]    |     |  - commons-codec:commons-codec:jar:1.6:compile
[INFO]    |     - org.slf4j:jcl-over-slf4j:jar:1.7.7:runtime
[INFO]    +- org.semarglproject:semargl-sesame:jar:0.6.1:compile
[INFO]    |  +- org.semarglproject:semargl-core:jar:0.6.1:compile
[INFO]    |  - org.semarglproject:semargl-rdfa:jar:0.6.1:compile
[INFO]    |     - org.semarglproject:semargl-rdf:jar:0.6.1:compile
[INFO]    +- com.google.guava:guava:jar:18.0:compile
[INFO]    +- com.google.inject:guice:jar:4.0-beta:compile
[INFO]    |  +- javax.inject:javax.inject:jar:1:compile
[INFO]    |  - aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- com.google.inject.extensions:guice-multibindings:jar:4.0-beta:compile
[INFO]    +- com.google.code.findbugs:jsr305:jar:2.0.1:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO]    +- org.apache.directory.studio:org.apache.commons.io:jar:2.4:compile
[INFO]    - net.sf.trove4j:trove4j:jar:3.0.3:compile

这是一个包含OWLAPI 4.0.2所有必需依赖项的.zip文件。 您只需将其解压缩并将所有这些.jar文件包含在您的项目中。

从以下网址下载.zip:https://www.dropbox.com/s/835qjm1xrhefy6s/Dependencias%20extras.rar?dl=0

最好的祝福。

链接地址: http://www.djcxy.com/p/20267.html

上一篇: Getting error in executing OWL API

下一篇: why base64 class is not found when code compiles ok and classpath is set