简体   繁体   中英

Loading owl file with Jena

I load several OWL files (RDF/XML serialization) with Jena as OntModel . For some files I get an error when reading them with ontoModel.read() :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpMessage .

I have org.apache.httpcore-sources.jar in the classpath.

The file which currently poses problem is: ontologydesignpatterns.org/cp/owl/timeindexedpersonrole.owl

I saved it with Protege as RDF/XML, trying with both extensions .owl and .rdf .

The code:

public static OntModel getOntologyModel(String ontoFile)
{   
    OntModel ontoModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
    try 
    {
        InputStream in = FileManager.get().open(ontoFile);
        try 
        {
            ontoModel.read(in, null);
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        LOGGER.info("Ontology " + ontoFile + " loaded.");
    } 
    catch (JenaException je) 
    {
        System.err.println("ERROR" + je.getMessage());
        je.printStackTrace();
        System.exit(0);
    }
    return ontoModel;
}

Many thanks for your help.

If you are using the binary download, put all the jars in the lib/ directory on the classpath. org.apache.httpcore-sources.jar isn't the right jar.. You seem to be missing at least httpclient-4.2.6.jar and httpcore-4.2.5.jar.

If you use maven, use the artifact:

<dependency>
 <groupId>org.apache.jena</groupId>
 <artifactId>apache-jena-libs</artifactId>
 <type>pom</type>
 <version>X.Y.Z</version>
</dependency> 

to get the same set, but managed by maven, or whatever builer you are using.

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