简体   繁体   中英

Jena Fuseki: Creation of Dataset does not work

I have Jena Fuseki database running on my localhost and I am trying to create a new dataset via the following Java code:

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

    return dataset;
}

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

My Java console shows the following output:

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)

The problem seems to be that the Java method tries to store the dataset in the location

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

with the unnecessary prefix of my local file system and I do not know how to remove this prefix.

The method you've used seems somewhat under-documented, but if you look at a similar method here: https://jena.apache.org/documentation/javadoc/tdb/org/apache/jena/tdb/TDBFactory.html#createDataset-org.apache.jena.tdb.base.file.Location-

with the signature

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

then it suggests that this factory method expects a path to a directory in your file system, not the url on which your server is listening. The name of the String -type argument is dir , which also indicates that a path to a directory is expected.

If you want to create a new dataset on a running fuseki server, consider making use of fuseki's HTTP-based administration protocol, described here: https://jena.apache.org/documentation/fuseki2/fuseki-server-protocol.html#datasets-and-services . This is not exactly a SPARQL query, and it uses http POST requests, but it should do what you want.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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