1

I am trying to run a simple example of a java program for owl ontology reasoning that i found online. It uses owl api and hermit reasoner. So i added the org.semanticweb.HermiT and owlapi-osgidistribution-4.0.2 libraries. Still i get the following exception :

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Provider
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at obligation.Obligation.main(Obligation.java:43)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Provider
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 25 more
Java Result: 1

I found in a similar question on stackoverflow that the solution is

You're missing the guava jars. For OWLAPI 4.0.2, you also need all other jars included in the maven dependencies. If you could not use Maven to build your code, you'll need to make sure all the dependencies are added manually.

i added that guava jars in my project but i didn't manage to solve the problem. Also i really don't know what are all that jars included in the maven dependencies. Could you please help me to solve this out?

2 Answers2

2

You can either use maven to do your build, or use the following shortcut: download the owlapi-osgidistribution jar file and uncompress it; you'll find a lib folder inside it, with all the necessary jars.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
0

The ClassNotFoundException tells you that the missing class is com.google.inject.Provider. This class is in Guice, not Guava, so you need to add the Guice jar to your project.

As you discovered, and as fge mentioned, this in turn requires the JSR-330 jar javax.inject which is where the javax.inject.Provider resides.

Breandán Dalton
  • 1,619
  • 15
  • 24
  • 1
    Not only that, but even those specific Guice annotations should be deprecated in favor of the JSR 330 annotations... I don't know owl but it seems to rely on very old stuff – fge Oct 07 '15 at 10:43
  • Thank you for your quick response. I added the guice jar and now i get the following error : Exception in thread "main" java.lang.NoClassDefFoundError: javax/inject/Provider at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at .... – Katerina Dimitraki Oct 07 '15 at 10:45
  • After i added your proposed library, i got the following exception : Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory i downloaded and the slf4j and because there are many libraries i added the whole folder but i continue to get the same error. I am new in Java and Netbeans so it is a bit difficult for me. – Katerina Dimitraki Oct 07 '15 at 12:02
  • The slf4j libraries can't be added by adding the folder. You need to add every jar in the folder separately (adding the folder will only include .class files that are in the folder) – Breandán Dalton Oct 07 '15 at 12:16
  • Is there any idea about this exception : Exception in thread "main" java.lang.NoClassDefFoundError: Lcom/google/common/collect/ImmutableList; ? I have already the javax.inject.jar that sb is reccomending. – Katerina Dimitraki Oct 07 '15 at 12:49
  • That's a curious one. com.google.common.collect.ImmutableList should be in the guava jar already. Check that it's still on your class path. – Breandán Dalton Oct 07 '15 at 13:00
  • I had removed the guava jar because i thought it was replaced by the guice. Now i get a new exception. Do you think that it is normal to need so many different jars for a basic java program for reasoning? I worry that maybe the problem is different, Still i just did copy paste the code. – Katerina Dimitraki Oct 07 '15 at 13:39
  • I'm surprised that there was no supporting makefile for, e.g. maven or ant, listing these dependencies. Still, while you are getting ClassNotFoundException, you can by trial and error discover the classes you need to add, and use google to search for the jars that contain those classes. You will eventually reach the end of the path. – Breandán Dalton Oct 07 '15 at 13:48
  • There is a pom file with all dependencies indeed. – Ignazio Oct 07 '15 at 15:58
  • I do not use maven. The program is as simple as that: OWLOntologyManager m=OWLManager.createOWLOntologyManager(); // We use the OWL API to load the Pizza ontology. OWLOntology o=m.loadOntologyFromOntologyDocument(IRI.create("http://www.cs.ox.ac.uk/isg/ontologies/UID/00793.owl")); // Now, we instantiate HermiT by creating an instance of the Reasoner class in the package org.semanticweb.HermiT. Reasoner hermit=new Reasoner(o); // Finally, we output whether the ontology is consistent. System.out.println(hermit.isConsistent()); } – Katerina Dimitraki Oct 08 '15 at 09:48
  • thanks a lot it works for me too !! when I changed owl api to 3.5 and I removed all others jar files ( javax, jsr semantic hermit ...) it needs oly the owlapi-distribution-3.5.0.api – Héla Apr 01 '16 at 09:39