'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?



Solution 1:[1]

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.

Solution 2:[2]

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("graph", graph);

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

fusekiServer.start();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jane Foster
Solution 2 joedavid