title: How can i use gems-in-a-jar with embedded JRuby?
body: <p>I would like to use the excellent <a href="http://sass-lang.com/" rel="noreferrer">Sass</a> as part of my build process. My build process is managed by <a href="http://gradle.org/" rel="noreferrer">Gradle</a>. That means writing a plugin to run Sass. Sass is Ruby, and Gradle is in Groovy, but since Groovy runs on the JVM, i can use <a href="http://jruby.org/" rel="noreferrer">JRuby</a> to run it, using the Java <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/index.html" rel="noreferrer">scripting API</a>. Gradle scripts get dependencies in the form of jar files; i can get JRuby from <a href="http://search.maven.org/#artifactdetails%7Corg.jruby%7Cjruby-core%7C1.6.7%7Cjar" rel="noreferrer">Maven Central</a>, but i will need to package Sass as a jar myself.</p>
  
  <p>I've tried to follow <a href="http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar" rel="noreferrer">Nick Sieger's gems-in-a-jar procedure</a> for doing this, but have had no success. No matter what i do, i just can't get JRuby to pick up the Sass gem.</p>
  
  <p>To isolate the problem, i have written a minimal Java (not Gradle) program which tries to use Sass via JRuby - i inventively call it JSass:</p>
  
  <ul>
  <li><a href="https://bitbucket.org/twic/jsass" rel="noreferrer">https://bitbucket.org/twic/jsass</a></li>
  </ul>
  
  <p>There are two or three interesting bits. The first is the script <a href="https://bitbucket.org/twic/jsass/src/tip/bin/generate-gem-jar.sh" rel="noreferrer">generate-gem-jar.sh</a>, which builds the gem jar:</p>
  
  <pre><code>gem install -i build/gems sass --no-rdoc --no-ri
  jar cf lib/gemsass.jar -C build/gems .
  </code></pre>
  
  <p>The second is the <a href="https://bitbucket.org/twic/jsass/src/tip/src/main/java/so/demo/JSass.java" rel="noreferrer">so.demo.JSass</a> class, which runs JRuby:</p>
  
  <pre><code>ScriptEngine rubyEngine = new ScriptEngineManager().getEngineByName("jruby");
  ScriptContext context = rubyEngine.getContext();
  context.setAttribute("inputFile", inputFile, ScriptContext.ENGINE_SCOPE);
  String script = IOUtils.toString(JSass.class.getResourceAsStream("sassdriver.rb"));
  rubyEngine.eval(script, context);
  </code></pre>
  
  <p>The third is the Ruby script which the main class tries to use to operate Sass:</p>
  
  <pre><code>require 'sass'
  template = File.load(inputFile)
  sass_engine = Sass::Engine.new(template)
  output = sass_engine.render
  puts output
  </code></pre>
  
  <p>The program is able to load the JRuby engine and execute the script, but it fails at <code>require 'sass'</code>, saying:</p>
  
  <pre><code>LoadError: no such file to load -- sass
    require at org/jruby/RubyKernel.java:1033
     (root) at &lt;script&gt;:1
  org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- sass
      at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:132)
      at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:90)
      at so.demo.JSass.main(JSass.java:24)
  Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- sass
  Exception in thread "main" javax.script.ScriptException: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- sass
      at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java:115)
      at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:93)
      at so.demo.JSass.main(JSass.java:24)
  Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- sass
  </code></pre>
  
  <p>What am i doing wrong?</p>