NoSuchMethod while trying to create SPARQL query with jena

I am trying to do some SPARQL queries using vc-db-1.rdf and q1.rq from ARQ examples. Here is my java code:

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.query.* ;
import com.hp.hpl.jena.query.ARQ;
import com.hp.hpl.jena.iri.*;
import java.io.*;
public class querier extends Object 
{
static final String inputFileName = "vc-db-1.rdf";
public static void main (String args[]) 
{
    // Create an empty in-memory model 
    Model model = ModelFactory.createDefaultModel();
    // use the FileManager to open the bloggers RDF graph from the filesystem
    InputStream in = FileManager.get().open(inputFileName);
    if (in == null) 
    {
        throw new IllegalArgumentException( "File: " + inputFileName + " not found");
    }
    // read the RDF/XML file
    model.read( in, ""); 
    // Create a new query
    String queryString = "PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?y ?givenName WHERE { ?y vcard:Family \"Smith\" . ?y vcard:Given  ?givenName . }";
    QueryFactory.create(queryString);
}
}

      

The compilation is fine. The problem is that the request is not even executed, but I am getting an error when I create it in the line

QueryFactory.create(queryString);

      

with the following explanation:

C:\Wallet\projects\java\ARQ_queries>java querier
Exception in thread "main" java.lang.NoSuchMethodError: com.hp.hpl.jena.iri.IRI.
resolve(Ljava/lang/String;)Lcom/hp/hpl/jena/iri/IRI;
    at com.hp.hpl.jena.n3.IRIResolver.resolveGlobal(IRIResolver.java:191)
    at com.hp.hpl.jena.sparql.mgt.SystemInfo.createIRI(SystemInfo.java:31)
    at com.hp.hpl.jena.sparql.mgt.SystemInfo.<init>(SystemInfo.java:23)
    at com.hp.hpl.jena.query.ARQ.init(ARQ.java:373)
    at com.hp.hpl.jena.query.ARQ.<clinit>(ARQ.java:385)
    at com.hp.hpl.jena.query.Query.<clinit>(Query.java:53)
    at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:68)
    at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
    at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
    at querier.main(querier.java:24)

      

How can I solve this? Thank.

+3


source to share


1 answer


It looks like you are missing the IRI library in the classpath (the IRI library is separate from the main Jena JAR). Jena has runtime dependencies on several other libraries that are included in lib

the Jena distribution directory . All of this should be in your classpath at runtime (but not necessarily at compile time).



+4


source







All Articles