简体   繁体   中英

How to start Fuseki server using Java code and upload OWL file to it using java code?

I want to start Fuseki server using Java code.Then I want to upload OWL file into it. Now I started using following CMD code and manually upload the file.Is there any possible way to do it using Java code? Server starting code using CMD.

    D:
    cd Fuseki
    cd jena-fuseki-1.0.1
    fuseki-server --update --mem /ds

Is there any possible way to run above code in JAVA code and upload a OWL file into Fuseki server?

The core idea of the solution is to use Jena ARQ API. You need to use class com.hp.hpl.jena.query.DatasetAccessor and .putModel() method.

This blog https://pinesong.ghost.io/how-to-upload-rdf-file-to-jena-fuseki-server-using-java-code gives the details.

This can be done using the fuseki as an embedded server. You can either opt for persistance using a triplestore TDB that Jena comes with or you can create an in-memory model. I'll show the case for the former but the idea remains the same for the latter.

//Creating a persistent triple store (Jena TDB)
String dir = "C:\\..."; // triplestore directory
Dataset dataset = TDBFactory.createDataset(dir);

//Loading an ontology stored on the disk
String ontDir = "C:\\...ontology.owl"; //Directory of your OWL file
Model graph = RDFDataMgr.loadModel(ontDir);

dataset.addNamedModel("..GraphURI..", graph);

// Starting the fuseki server
FusekiServer fusekiServer = FusekiServer.create()
            .port(3001)
            .add("/ds", dataset, true)
            .build();

fusekiServer.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