简体   繁体   中英

Using Jena with Pellet; NoClassDefFoundError Exception

I'm trying to use Jena 2.12.1 with Pellet; I downloaded the latest Apache Jena library from their site Jena 2.12.1 .

First, I downloaded Pellet 2.3.1 and imported the JENA libraries. Unfortunately, org.mindswap.pellet.jena.PelletReasonerFactory couldn't be resolved, and thus, I couldn't instantiate a reasoner.

Then, I downloaded multiple versions the jar file pellet-jena-2.3.2 (tried 2.3.1 and 2.3.0). This resolved org.mindswap.pellet.jena.PelletReasonerFactory . However it caused the exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/mindswap/pellet/utils/progress/ProgressMonitor
at org.mindswap.pellet.jena.PelletReasoner.bind(PelletReasoner.java:95)
at org.mindswap.pellet.jena.PelletReasoner.bind(PelletReasoner.java:53)
at com.hp.hpl.jena.rdf.model.ModelFactory.createInfModel(ModelFactory.java:261)
at code.BasicOWLHandler.main(BasicOWLHandler.java:678)
Caused by: java.lang.ClassNotFoundException: org.mindswap.pellet.utils.progress.ProgressMonitor


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)
... 4 more

My code:

import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.reasoner.Reasoner;

public class Test {
public static void main (String [] args)
{
    Reasoner reasoner = PelletReasonerFactory.theInstance().create();

    // create an empty model
    Model emptyModel = ModelFactory.createDefaultModel( );

    // create an inferencing model using Pellet reasoner
    InfModel model = ModelFactory.createInfModel( reasoner, emptyModel );
}   
}

What is the problem? is there a better way to use jena 2.12.1 with Pellet (any version)?

The error message says it can't find org.mindswap.pellet.utils.progress.ProgressMonitor when called from org.mindswap.pellet.jena.PelletReasoner.bind . That looks like the classpath does not have all the necessary Pellet jars. It is nothing to do with Jena.

However, see http://clarkparsia.com/pellet/faq/different-jena-version/ . Pellet is unlikely to work perfectly with Jena 2.12.1 due to the 2+ year gap.

You may wish to try this fork or one of its branches: https://github.com/ansell/pellet (no recommendation either way)

The link you give to Jena is not the master site - it looks like a mirror of http://www.apache.org/dist/jena .

If anybody comes across this and wants to use Jena 2.13 together with Pellet, it's possible since July 14, 2015 using Pellet 2.4 . See commit #7b07bf .

Get get it up and running you just have to build the JARs yourself by cloning their repo and running mvn compile . They also include an example using Jena 2.13.

To use Pellet with Jena simple follow the instruction on their FAQs :

// ontology that will be used
String ont = "http://www.mindswap.org/2004/owl/mindswappers";

// create an empty ontology model using Pellet spec
OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );   

// read the file
model.read( ont );

使用包括JENA兼容库的颗粒2.3.0(2011年8月22日)代替颗粒2.3.1已解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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