The problem is probably in the exec somewhere.

The exec'ed process is asynchronous so you have to wait for it to finish.

If there are any errors, you won't see them.

Try something like this which worked for me:

* ProcessBuilder.inheritIO to see output.
* process.waitFor() for waiting until finished.

Also the exec'ed process may not have the same environment as when you use the command line, for example. I put in absolute paths because I ran this in Eclipse which does not share the command line setup of PATH.

public static void main(String[] args) throws Exception {
    FileOps.ensureDir("dataset");
    FileOps.clearAll("dataset");
    Process process = new ProcessBuilder(
            "/home/afs/jlib/apache-jena/bin/tdb2.tdbloader",
            "--loc=dataset",
            "--loader=parallel",
            "/home/afs/tmp/D.ttl")
        .inheritIO()
        .start();
    int rc = process.waitFor();
    if ( rc != 0 ) {
        System.err.println("Exit "+rc);
        System.exit(0);
    }
    Dataset dataset = TDB2Factory.connectDataset("dataset");
    Txn.exec(dataset,  TxnType.READ, ()->{
        RDFDataMgr.write(System.out, dataset, Lang.TRIG);
    });
}

    Andy

On 18/06/2019 12:00, Scarlet Remilia wrote:
I am sorry for mistake.

It should be



Dataset dbdataset = TDB2Factory.connectDataset("dataset");



“dataset” is the location of the TDB2.And I also tried assembler file without 
working well.



Thanks!



Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10



________________________________
From: Andy Seaborne <[email protected]>
Sent: Tuesday, June 18, 2019 6:34:10 PM
To: [email protected]
Subject: Re: Command-line tools and JAVA API



On 18/06/2019 10:36, Scarlet Remilia wrote:
Hello everyone,

I bulk load some RDF files into a TDB2 in my Java code, like,
Runtime.getRuntime().exec(“tdb2.tdbloader --loc=dataset --loader=parallel  
a.rdf b.rdf c.rdf”);

But when I connect to the dataset by java API, like
Dataset dbdataset = TDB2Factory.assembleDataset("dataset");

TDB2Factory.connectDataset

I get an error with "assembleDataset"

11:32:00 WARN  LocatorFile               :: File unreadable (but
exists): dataset Exception: dataset (Is a directory)
Exception in thread "main" org.apache.jena.sparql.ARQException: Failed
reading assembler description: Not found: dataset


I get a empty dataset, and cannot query any data.
Further, I add some data into the same TDB2 by java api, like
dbdataset.begin(ReadWrite.WRITE);
          UpdateRequest updateRequest = UpdateFactory.create(
                  "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" +
                          "INSERT DATA\n" +
                          "{ \n" +
                          "  <http://example/book1> dc:title \"A new book\" 
;\n" +
                          "                         dc:creator \"A.N.Other\" 
.\n" +
                          "}");
          UpdateProcessor updateProcessor =
                  UpdateExecutionFactory.create(updateRequest, dbdataset);
          updateProcessor.execute();
          dbdataset.commit();
          dbdataset.close();
I can query the data of book1 only by java api, and tdb2.tdbquery commandline 
tool can query all data include book1 and RDF files.

So how to make it work?

Btw, is there any tdb2 tdbloaer Java API?


Thank you very much

Jason

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10



Reply via email to