Hello,
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
that
will need to access the Java API of dotCMS) .
For now this needs to work on Windows, of course, in the end it should
work
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
output
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-1.6.5.1.jar -IC:/dotCMS_SASS -rcompass-gems.jar
-S
irb
In the repl I can then require rubygems and then compass without
problems.
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(‘\’, ‘/’),
“-rcompass-gems.jar”});
Which would seem to be enough considering I could start the repl above
with
the same parameters.
Here libPath is the absolute directory (programmatically obtained) where
compass-gems.jar and jruby-complete-1.6.5.1.jar are located (see also a
bit
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 –
rubygems
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1038)
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
the
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-1.6.5.1.jar and running atom dotCMS 1.9.4.1.
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
work
better.
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
load.
Thank you for your time,
Maarten Daalder
@MLeoDaalder
[1]
http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar