2
votes

I am trying to execute following code.

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);
}
}

It is generating following error.

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Provider 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$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.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$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at test.main(test.java:18) Caused by: java.lang.ClassNotFoundException: com.google.inject.Provider at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 25 more

Please some body help me out. thanks in advance.

1

1 Answers

4
votes

what jars are you including in your classpath ?

It looks like you're missing some google guice dependencies. I suggest to use some dependency management tool such as maven or gradle

for instance, i solved that issue by using a maven dependency to

net.sourceforge.owlapi:owlapi-osgidistribution:4.0.2

on a maven project with your Snippet class as a main class.

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

If you want to run it without using a dependency manager, make sure to have the following jars in your classpath (the following list was obtained with a maven dependency tree command)

[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