Jena Fuseki:创建数据集不起作用

时间:2018-01-21 16:15:30

标签: java jena fuseki

我在我的localhost上运行了Jena Fuseki数据库,我正在尝试通过以下Java代码创建一个新的数据集:

public static Dataset createDataset() {
    Dataset dataset = TDBFactory.createDataset("http://localhost:3030/testDataset");

    return dataset;
}

public static void main(String[] argv) {
    createDataset();
}

我的Java控制台显示以下输出:

Exception in thread "main" org.apache.jena.tdb.TDBException: Does not exist: /Users/Philip/IdeaProjects/Squirrel_copy/http:/localhost:3030/testDataset/
at org.apache.jena.tdb.setup.DatasetBuilderStd.error(DatasetBuilderStd.java:321)
at org.apache.jena.tdb.setup.DatasetBuilderStd.checkLocation(DatasetBuilderStd.java:139)
at org.apache.jena.tdb.setup.DatasetBuilderStd.build(DatasetBuilderStd.java:161)
at org.apache.jena.tdb.setup.DatasetBuilderStd.create(DatasetBuilderStd.java:90)
at org.apache.jena.tdb.StoreConnection.make(StoreConnection.java:208)
at org.apache.jena.tdb.StoreConnection.make(StoreConnection.java:215)
at org.apache.jena.tdb.transaction.DatasetGraphTransaction.<init>(DatasetGraphTransaction.java:65)
2018-01-21 17:08:03,092 [main] ERROR [o.a.j.info                    ] - <Does not exist: /Users/Philip/IdeaProjects/Squirrel_copy/http:/localhost:3030/testDataset/>
at org.apache.jena.tdb.sys.TDBMaker._create(TDBMaker.java:55)
at org.apache.jena.tdb.sys.TDBMaker.createDatasetGraphTransaction(TDBMaker.java:42)
at org.apache.jena.tdb.TDBFactory._createDatasetGraph(TDBFactory.java:89)
at org.apache.jena.tdb.TDBFactory.createDatasetGraph(TDBFactory.java:71)
at org.apache.jena.tdb.TDBFactory.createDataset(TDBFactory.java:55)
at org.apache.jena.tdb.TDBFactory.createDataset(TDBFactory.java:51)
at org.aksw.simba.squirrel.sink.RDFSink.createDataset(RDFSink.java:43)
at org.aksw.simba.squirrel.sink.RDFSink.main(RDFSink.java:49)

问题似乎是Java方法试图将数据集存储在位置

/Users/Philip/IdeaProjects/Squirrel_copy/localhost:3030/testDataset/

使用我本地文件系统的不必要前缀,我不知道如何删除此前缀。

2 个答案:

答案 0 :(得分:0)

您使用的方法似乎有些记录不足,但如果您在此处查看类似的方法:https://jena.apache.org/documentation/javadoc/tdb/org/apache/jena/tdb/TDBFactory.html#createDataset-org.apache.jena.tdb.base.file.Location-

带签名的

public static Dataset createDataset(org.apache.jena.tdb.base.file.Location location)

然后它表明此工厂方法需要一个指向文件系统中目录的路径,而不是服务器正在侦听的URL。 String - 类型参数的名称是dir,它还表示预期到目录的路径。

如果要在运行的fuseki服务器上创建新数据集,请考虑使用fuseki的基于HTTP的管理协议,如下所述:https://jena.apache.org/documentation/fuseki2/fuseki-server-protocol.html#datasets-and-services。这不完全是一个SPARQL查询,它使用http POST请求,但它应该做你想要的。

答案 1 :(得分:0)

public void setup() throws IOException 
{ 
  ds = DatasetFactory.createTxnMem();
  server = FusekiServer.create().add("/ds", ds).build();
  server.start();
}