您好,我刚刚开始使用 Jena,想要运行一些 SPARQL 查询。当我尝试运行基本选择查询时,出现以下异常:
Caused by: java.lang.NoSuchMethodError: com.hp.hpl.jena.rdf.model.impl.RDFWriterFImpl.setBaseWriterClassName(Ljava/lang/String;Ljava/>lang/String;)Ljava/lang/String;
at org.openjena.riot.SysRIOT.wireIntoJena(SysRIOT.java:93)
at org.openjena.riot.RIOT.init(RIOT.java:61)
at com.hp.hpl.jena.query.ARQ.init(ARQ.java:451)
at com.hp.hpl.jena.query.ARQ.<clinit>(ARQ.java:456)
at com.hp.hpl.jena.query.Query.<clinit>(Query.java:62)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:80)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:52)
at com.qmap.core.server.jena.GetExistingRelationships.appendValidProperties(GetExistingRelationships.java:153)
我的java代码是:
String queryString = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX ns: <http://www.semanticweb.org/ontologies/2012/1/Ontology1328444427428.owl#> SELECT ?r WHERE { ns:within rdfs:range ?r . }";
Query query = QueryFactory.create(queryString, Syntax.syntaxSPARQL);
QueryExecution qexec = QueryExecutionFactory.create(query, m) ;
try {
Iterator<QuerySolution> rs = qexec.execSelect() ;
for ( ; rs.hasNext() ; )
{
QuerySolution soln = rs.next() ;
System.out.println(soln.toString());
}
} finally { qexec.close() ; }
其中“m”是 OntModel 类型。从我读到的内容来看,问题可能出在我的 Jena 库上 - 但是我更新到最新的 Jena 版本,但仍然没有运气。可能缺少某些东西,但是堆栈跟踪中引用的包在那里。
这是我的 jena 库文件:
任何帮助将不胜感激。
最佳答案
你的代码对我有用。看起来 jena-core 不在运行时类路径上。
这可能是因为您的类路径上还有其他内容 - 行号与 ARQ 2.9.4 不太一致。
关于sparql - 在 JENA 中运行简单 SPARQL 查询时出现 NoSuchMethod 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13055630/