A researcher and developer that is passionate about Semantic Web, Machine Learning and Big Data

How to upload RDF file to Jena Fuseki server using Java?

Fuseki is a semantic data publishing platform/server. It works like Apache HTTP server (which is designed to host static web sites), you need to provide data files for it to serve. However, they are quite different in terms of two main aspects:

  1. Fuseki serves RDF data while Apache HTTP serves HTML files
  2. Fuseki implements the SPARQL query language and protocol for RDF while Apache HTTP targets for HTTP protocol

In order to make your RDF data accessible from Fuseki, you need to import the RDF data into Fuseki before you can query using SPARQL.

The Fuseki documentation has very limited guidance on how to do this using Java. Thus, the purpose of this post is to illustrate how to upload RDF file to a running Fuseki server using Java code.

The core idea of the solution is to use Jena ARQ API.

Note You need to import the relevant Jena API classes in your Java class

import com.hp.hpl.jena.query.DatasetAccessor;
import com.hp.hpl.jena.query.DatasetAccessorFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

Step 1 Create an HTTP Dataset Accessor

String serviceURI = "http://localhost:3030/ds/data";
DatasetAccessorFactory factory;
DatasetAccessor accessor;
accessor = factory.createHTTP(serviceURI);

Step 2 Create a Jena Data Model from an InputStream

InputStream in;
Model m = ModelFactory.createDefaultModel();
String base = "http://test-projects.com/";
m.read(in, base, "RDF/XML");

Step 3 Put the Data Model to Fuseki server through the Dataset Accessor


Step 4 Check if uploaded successful

go to http://localhost:3030/control-panel.tpl

input this SPARQL query in the query form,

select * {?s ?p ?o}

and you will see all the triple data retrieved from the uploaded data file.

comments powered by Disqus