Ruby gem to convert marc4j and ruby-marc records to/from each other under JRuby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Build Status


Convert ruby-marc MARC::Record objects to/from java marc4j org.marc4j.marc.Record objects under JRuby.

Useful if you're working in JRuby and need to use a marc4j reader, or if you want to use a standard ruby-marc reader but spool some functionality out to java code that relies on marc4j obejcts.


chruby jruby # or however you use JRuby
gem install marc-marc4j

Creating a converter

You can load up the marc4j jar file in three ways:

  • Just require it yourself at the top of a file. MARC::MARC4J will detect that it's already been loaded and not try to load another copy.
require 'marc/marc4j'
require '../jarfiles/marc4j_2.5.jar'
converter = # will use above jarfile
  • Call>'/path/to/marc4j/jar/directory') to state where your jar files live
require 'marc/marc4j'
converter = => '../jarfiles/') # Load all .jar files in ../jarfiles
  • Call without a :jarfile argument to use the bundled marc4j jarfile.
require 'marc/marc4j'

converter =  # uses bundled marc4j jarfile unless marc4j is already loaded


You can also pass in a logger object, that responds to the normal debug/warn/etc.

require 'marc/marc4j'
require 'my/logging/library'

logger  =
converter =>logger)

Doing the conversions

A converter only has two useful methods:

  • marc4j = converter.rubymarc_to_marc4j(r) will convert a ruby-marc MARC::Record object to a marc4j record
  • rmarc = converter.marc4j_to_rubymarc(j) will convert a marc4j record to a ruby MARC::Record object

Implementation details worth knowing

  • The converter doesn't do any caching at all, so if you want to only do the conversion once, you need to stick the result somewhere.

  • marc4j records are built using a marc4j factory object. This defaults to a org.marc4j.marc.MarcFactory, but will use whatever class is in the java system property org.marc4j.marc.MarcFactory (as seen in the marc4j source code).


Copyright (c) 2013 Bill Dueber

See {file:LICENSE.txt} for details.