Jena Ruby Setup: Mac OS X


The JRuby Downloads page offers various forms and versions of JRuby. Unless you're interested in modifying JRuby, all you need is the "JRuby x.y.z Binary .jar". See for a quick rundown on how to use it.

The following notes and code are based on my local configuration, so you will have to make appropriate accommodations. After installing JRuby, I set up a nearby jena_hax directory:


Downloads, etc.

You'll need to download a few files and store them in jena_hax.

  • jena.rb

    jena.rb is a small (~200 line) library that provides Ruby bindings to Jena.

  • jenabean

    jenabean uses Jena's flexible RDF/OWL API to persist Java beans.

Here are some helper scripts I wrote. Save them as files in jena_hax, then adjust the path and file names appropriately.

Here's rj, used to start up jirb (JRuby's version of Interactive Ruby):

# rj - run jirb
# Set up PATH, then run jirb with a simple prompt.

jirb --simple-prompt

Here's js.rb. We'll use this in jirb to bring in jarfiles, etc:

# js.rb - jena startup code

home  = ENV['HOME']
jlib  = "#{home}/...ARQ or Jena directory.../lib"
patt  = "#{jlib}/*.jar"
files = Dir.glob(patt) + %w[ jenabean-1.0.5.jar jena.rb ]
files.each {|file| require file } 

Finally, make rj executable and grab a copy of song.owl:

% chmod +x rj
% curl > song.owl

Trial Run

OK; let's make sure that things are working:

% rj
>> require 'js'
=> true
>> m = Jena.create_model
=> #<Java::ComHpHplJenaOntologyImpl::OntModelImpl:0x6e8e76>
>> m.write(System.out)
    xmlns:owl="" > 
=> #<Java::ComHpHplJenaRdfModelImpl::ModelCom:0xc93cf5>

If that worked, you can wander off to some Jena_Ruby_Hacks. If not, get in touch and we'll try to figure out what went wrong.

This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r3 - 02 Jul 2011, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email