简体   繁体   English

使用 Java jena 插入 SPARQL 查询以在 fuseki 中上传三元组

[英]Insert SPARQL query with Java jena to upload triples in fuseki

I'm trying to create an INSERT query within my Java web application using the jena framework.我正在尝试使用 jena 框架在我的 Java Web 应用程序中创建一个 INSERT 查询。 I want to insert some triples to a specific named graph in my Fuseki triple store.我想向我的 Fuseki 三元组存储中的特定命名图插入一些三元组。 I have tried using the code below我试过使用下面的代码

UpdateRequest update = UpdateFactory.create("INSERT DATA { graph <http://graph/my> { "+ string_triples + "}}");
UpdateProcessor processor = UpdateExecutionFactory.createRemote(update, "http://fusekidomain/ds/sparql");
processor.execute();

but it hasn't worked, I get a " java.lang.ClassNotFoundException: org.apache.http.protocol.HttpContext " error.但它没有用,我得到一个“ java.lang.ClassNotFoundException: org.apache.http.protocol.HttpContext ”错误。

I'm guessing I'm missing something in my code but I'm not sure what it is.我猜我的代码中遗漏了一些东西,但我不确定它是什么。

java.lang.ClassNotFoundException : there is at least one jar missing from the classpath of your program. java.lang.ClassNotFoundException :程序的类路径中至少缺少一个 jar。

Either use maven or other build tool to manage the dependencies or put all the jars from the Jena distribution lib directory on the classpath.使用 maven 或其他构建工具来管理依赖项,或者将 Jena 分发 lib 目录中的所有 jar 放在类路径中。

Check for possible dependency conflicts in your project.检查项目中可能存在的依赖冲突。 Sometimes this error happens when another dependency is not using the same version of a library imported by another dependency (see this post ).有时,当另一个依赖项未使用由另一个依赖项导入的库的相同版本时,会发生此错误(请参阅这篇文章)。

If your project is a maven project, you can list all dependencies with the command:如果你的项目是 maven 项目,你可以使用命令列出所有依赖项:
mvn dependency:tree -Dverbose

Hope it helps;)希望能帮助到你;)

Thank you both for your answers.谢谢你们的回答。 It turns out I was indeed missing some jars and I had one jar that was duplicate, hence the no class found exception.事实证明我确实遗漏了一些罐子并且我有一个重复的罐子,因此没有发现类异常。 When I added them it worked fine.当我添加它们时,它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM