简体   繁体   English

使用owl API的Java程序中的异常

[英]Exception in java program, using owl api

I am trying to run a simple example of a java program for owl ontology reasoning that i found online. 我正在尝试为我在网上找到的猫头鹰本体论推理运行一个Java程序的简单示例。 It uses owl api and hermit reasoner. 它使用猫头鹰api和隐士推理程序。 So i added the org.semanticweb.HermiT and owlapi-osgidistribution-4.0.2 libraries. 因此,我添加了org.semanticweb.HermiT和owlapi-osgidistribution-4.0.2库。 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 我在关于stackoverflow的类似问题中发现解决方案是

You're missing the guava jars. 你想念番石榴罐子。 For OWLAPI 4.0.2, you also need all other jars included in the maven dependencies. 对于OWLAPI 4.0.2,您还需要maven依赖项中包括的所有其他jar。 If you could not use Maven to build your code, you'll need to make sure all the dependencies are added manually. 如果您不能使用Maven构建代码,则需要确保手动添加了所有依赖项。

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. 我也真的不知道Maven依赖项中包含的所有jar。 Could you please help me to solve this out? 您能帮我解决这个问题吗?

You can either use maven to do your build, or use the following shortcut: download the owlapi-osgidistribution jar file and uncompress it; 您可以使用maven进行构建,也可以使用以下快捷方式:下载owlapi-osgidistribution jar文件并解压缩; you'll find a lib folder inside it, with all the necessary jars. 您会在其中找到一个lib文件夹,其中包含所有必需的jar。

The ClassNotFoundException tells you that the missing class is com.google.inject.Provider . ClassNotFoundException告诉您缺少的类是com.google.inject.Provider This class is in Guice, not Guava, so you need to add the Guice jar to your project. 此类在Guice中,而不是Guava中,因此您需要将Guice jar添加到您的项目中。

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. 正如您所发现的,并且正如fge所提到的,这又需要JSR-330 jar javax.inject,它是javax.inject.Provider所在的位置。

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

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