Question regarding the combination of embedded JRuby and gems-in-a-jar


I’m currently creating a plugin for dotCMS, a Java CMS, such that it is
possible to use Sass/Compass stylesheets, and as such I’m trying to use
JRuby to do this (this will require one or more Sass/Compass plugins
will need to access the Java API of dotCMS) .
For now this needs to work on Windows, of course, in the end it should
wherever the JVM runs.

I’ve managed to get the gems (by installing compass) jarred up using the
blog post by Nick S. [1] (only change is that I just zipped the
directory, couldn’t immediately get the command to run as is).
And when I test this on the command line I can get it to work (from any
directory, the gems in a jar is in the C:/dotCMS_SASS directory,
jruby-complete.jar was in another directory) using:
java -jar jruby-complete- -IC:/dotCMS_SASS -rcompass-gems.jar

In the repl I can then require rubygems and then compass without
However when I try the same embedded, it can’t even find rubygems, never
mind compass.

I’m initializing a RubyConfigInstance with the following parameters:
RubyInstanceConfig config = new RubyInstanceConfig();
config.processArguments(new String[] {“-I” + libPath.replace(‘\’, ‘/’),
Which would seem to be enough considering I could start the repl above
the same parameters.
Here libPath is the absolute directory (programmatically obtained) where
compass-gems.jar and jruby-complete- are located (see also a
below for more details).

The Ruby runtime instance is then created using:
Ruby ruby= JavaEmbedUtils.initialize(Arrays.asList(), config);
Using that I can do the simple stuff such as:
RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
evaler.eval(ruby, “puts "Hello from the jRuby World!"”);

However when I do this:
evaler.eval(ruby, “require ‘rubygems’”);
then I get:
org.jruby.exceptions.RaiseException: (LoadError) no such file to load –
at org.jruby.RubyKernel.require(org/jruby/
at #Class:0x37de84.(root)(:1)

And I can’t require compass either.

Can you please advise what I need parameters I need to add to do to get
gems in a jar to load in an embedded situation?

I’m using JDK1.6_u26, 32 bit, on Windows XP, and I’m currently using the
jruby-complete- and running atom dotCMS
I’ve before tried the ‘plain’ jruby.jar before, however since I got the
missing rubygems I’ve tried to use jruby-complete to see if that would

It would seem, though I can’t verify, that the jruby jar is loaded from
inside another jar by the dotCMS classloader (which is a Tomcat6 root
deployment), however I’m not sure this should matter since I can put the
jruby jar on any place and run irb and get compass (and rubygems) to

Thank you for your time,
Maarten Daalder


Since writing my question I’ve found out that dotCMS contains it’s own
version of jruby.jar [1].

However, I have also figured out how to evade it, through extending an

It turns out to be a fairly generalized way of getting a ‘copy’ of the
hierarchy (of course just from the jars that you include) based from
the system classloader (the JRE). This turned out to be what we needed.
I’ve also added a way to inject some classes (and their
superclasses/interfaces) from outside the jars that you include. This
you can use ‘bridge’ classes/interfaces so that you won’t need to use a
of reflection (except to create a new instance of course).

I hope this will help future developers trying to use JRuby in a system
already uses some other, older, locked down version.

–Maarten Daalder

[1] jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (Java HotSpot™
Client VM 1.7.0_01) [x86-java]

On 11 January 2012 16:59, MLeo [email protected] wrote:

I’ve managed to get the gems (by installing compass) jarred up using the
mind compass.

I’ve before tried the ‘plain’ jruby.jar before, however since I got the

JRuby 1.1.6: Gems-in-a-jar

View this message in context:
Sent from the JRuby - User mailing list archive at