3

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.

ecrin
  • 91
  • 1
  • 7
  • please insert project structure, lib folder – Safwan Hijazi Jun 10 '15 at 21:24
  • I am able to load your file with your code. Make sure that you are passing owl file with correct name. Code is correct. – Haroon Lone Jun 11 '15 at 05:36
  • Thanks. I triple-checked, the file name is correct and the file exists. The error is actually coming from `org.apache.jena.riot.system.stream.LocatorHTTP.performOpen(LocatorHTTP.java:41)`. I also tried to put the base name as arg of the read method, but same error for the same file. Might be a stupid error somewhere, but I do not manage to spot it. – ecrin Jun 11 '15 at 07:12
  • The file linked has imports to other ontologies - one of them might be the problem. I'd try loading each one to see if anything useful emerges. – Ignazio Jun 11 '15 at 07:26
  • Thanks, you're right that might the imports. There is actually a chain of imports; other files pose problem as well, which make the whole stuff quite cumbersome. I think I will just hard-code the few classes of my initial file... – ecrin Jun 11 '15 at 08:19
  • `ontoModel.read(ontoFile);` will work (unless quite old Jena) if the file name has an extension. – AndyS Jun 11 '15 at 08:19
  • Reading the file directly does not work (for this file only) and hit the same error. Someone else got a similar pb when reading owl file with imports, but no solution: http://stackoverflow.com/questions/29850654/how-to-read-ontology-file-with-owlimports-in-jena. Thanks to all for your feedback. – ecrin Jun 11 '15 at 08:25

1 Answers1

1

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.

AndyS
  • 16,345
  • 17
  • 21
  • Hello, thanks, that was it! Simply missing the good libraries to handle the imports. Now it works :) – ecrin Jun 11 '15 at 09:26