Owl file upload with Jena

I am downloading multiple OWL (RDF / XML Serialization) files using 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 that is currently asking the problem: ontologydesignpatterns.org/cp/owl/timeindexedpersonrole.owl

I saved it with Protege as RDF / XML using both extensions .owl

and .rdf

.

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.

+3


source to share


1 answer


If you are using binary loading, place all jars in the lib / directory in the classpath. org.apache.httpcore-sources.jar is not the correct jar .. It seems that you are missing at least httpclient-4.2.6.jar and httpcore-4.2.5.jar.

If you are using maven use 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 kit but managed by maven, or whatever cooler you use.

+1


source







All Articles