Sam
Sam

Reputation: 1509

TDB Jena Querying

I am trying to query in Java with Jena using TDB. So basically i got an n3 file name song.n3 and using this file I want to use this with TDB. So I have created a directory which is generated in my Java1 folder (Netbeans project folder) and then I have the source of the actual n3 file. After running this code I am having the error "java.lang.NoClassDefFoundError". Basically debugging the code lead to the error being caused by the line : Dataset dataset = TDBFactory.createDataset(directory);. I am not too sure why this error is caused could it be that it because my directory is empty with no model.

public static void main(String[] args) throws IOException {
   String directory = "./tdb";
   Dataset dataset = TDBFactory.createDataset(directory);
   Model tdb = dataset.getDefaultModel();
   String source = "C:\\Users\\Name\\Documents\\NetBeansProjects\\Java1\\src\\song.n3";
   FileManager.get().readModel( tdb, source, "N3" );
   String queryString = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT * WHERE { ?x owl:sameas ?y }";

   Query query = QueryFactory.create(queryString);

   QueryExecution qe = QueryExecutionFactory.create(query, tdb);
   ResultSet results = qe.execSelect();

   ResultSetFormatter.out(System.out, results, query);

   qe.close();
 }
}

Upvotes: 2

Views: 1359

Answers (1)

Manuel Salvadores
Manuel Salvadores

Reputation: 16525

This should be a problem with your CLASSPATH, when I use TDB I have the following script to load the Jena-TDB libraries into my classpath ..

#!/bin/bash
CP="."
for i in ./TDB-0.8.9/lib/*.jar ; do
    CP=$CP:./TDB-0.8.9/lib/$i
done
export CLASSPATH=$CP

It is bash but very easy to translate into a Windows script. Bottom line, make sure that all the jars in /lib/ directory are in the CLASSPATH. Anyway, it would help it you give the complete java.lang.NoClassDefFoundError where the class not found is shown, that would give you a hint of what it is missing. Probably some of the logging libs that are not shipped inside the jena distribution.

Also, watch out for that owl:sameas predicate. SPARQL and RDF are case sensitive and the correct predicate is owl:sameAs.

Upvotes: 3

Related Questions