Generate RDF file in Java
In this example we are going to generate our first RDF( Resource Description File). This example generates a RDF file with the use of "Jena". Jena is a java API to create and manipulate RDF graphs.
To create RDF file we do need to import following packages:
- "com.hp.hpl.jena.rdf.model" : for creating and manipulating model resources.
- "com.hp.hpl.jena.vocabulary": for creating VCARD vocabulary.
To create model we have used createDefaultModel() of ModelFactory, which in turn returns an object of Model interface.
Model model = ModelFactory.createDefaultModel();
To create resource we have used createResource() method of Model interface. Now we can add properties in this model resource by using the "addProperty()" method.
GenerateRDF.java
import java.io.*;
|
To run the example you have to follow these steps:
- Create and save the code as GenerateRDF.java
- Add "jena.jar, icu4j_3_4.jar, iri.jar, commons-logging-1.1.1.jar, xercesImpl.jar" to your classpath.
- Compile GenerateRDF file and
- Run GenerateRDF class file
You will get following output on your command prompt.