Question

I'm trying to embed jruby in a weblogic app to run sass/compass with no luck ;-( This is what've done so far:

  1. Install sass/compass GEMS:

    java -jar jruby-complete-1.7.10.jar -S gem install -i . compass --no-rdoc --no-ri
    
  2. Create a jar that contains all the gems

    jar uf jruby-complete-1.7.10.jar -C sass-compass . 
    
  3. Check that the new jruby-complete-1.7.10.jar contains all the gems:

    java -jar jruby-complete-1.7.10.jar -S gem list
    
    *** LOCAL GEMS ***
    bouncy-castle-java (1.5.0147)
    chunky_png (1.2.9)
    compass (0.12.2)
    fssm (0.2.10)
    jruby-openssl (0.9.3)
    json (1.8.0 java)
    krypt (0.0.1)
    krypt-core (0.0.1 universal-java)
    krypt-provider-jdk (0.0.1)
    rake (10.1.0)
    rdoc (4.0.1)
    sass (3.2.14)  
    

So far, so good, I verify that my new uber jruby-complete-1.7.10.jar contains sass and compass gems

Enters weblogic (Weblogic 11 - Oracle 10.3.6)

  1. I create a WebApp with a servlet that uses JRuby to compile sass/compass css and put it inside an EAR
  2. Deploy the ear so the structure is like:

    MyEAR
      |-APP-INF
      |    |-classes
      |    |-lib
      |        |-jruby-complete-1.7.10.jar <- my jruby jar that contains sass/compass gems
      |-META-INF
      |-MyWAR
           |-META-INF
           |-WEB-INF
                |-classes
                |     |-MyServlet.class <- the servlet that compiles sass
                |-lib
                |-web.xml
    

When I call the servlet to compile some sass/compass css, I get the following error:

LoadError: no such file to load -- sass/plugin
require at org/jruby/RubyKernel.java:1083
require at classpath:/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55

(root) at :2

In order to compile my sass/compass styles I've to run the following ruby script:

require 'rubygems'
require 'sass/plugin'
require 'sass/engine'
source = '...the scss code....'
engine = Sass::Engine.new(source,{ :syntax => :scss,                                       :compass => {:css_dir => '/styles',:js_dir => '/scripts',images_dir => '/images'} })
result = engine.render

So in my servlet I use jruby like:

ScriptingContainer rubyEngine = new ScriptingContainer(LocalContextScope.CONCURRENT);
String rubyScript = ...
final StringWriter rawScript = new StringWriter();
rawScript.append(rubyScript);
rubyScript.flush();
String compiledCSS = rubyEngine.runScriptlet(theScript)
               .toString();

** NO LUCK ** I got the LoadError: no such file to load -- sass/plugin

So I tried to set the LOAD_PATH like:

List<String> paths = new ArrayList<String>();
paths.add("classpath:/gems/sass-3.2.14/lib");
rubyEngine .setLoadPaths(paths);

** NO LUCK EITHER **

¿any idea?

Thanks in advance

Was it helpful?

Solution

The solution as Tom's clue said was putting sass/compass gems path at the LOAD_PATH.

So the script to make sass/compass run under weblogic 10.3.6 was:

sassGemDir = 'D:/compass-gems/gems/sass-3.2.13/lib'
compassGemDir = 'D:/compass-gems/gems/compass-0.12.2/lib'
chunkyPngGemDir = 'D:/compass-gems/gems/chunky_png-1.2.9/lib'
fssmGemDir = 'D:/compass-gems/gems/fssm-0.2.10/lib'
$LOAD_PATH.insert(0,sassGemDir,remoteSassGemDir,compassGemDir,chunkyPngGemDir,fssmGemDir)

require 'rubygems'
require 'sass/plugin'
require 'sass/engine'
source = '...the scss code....'
engine = Sass::Engine.new(source,{ :syntax => :scss,:compass => {:css_dir => '/styles',:js_dir => '/scripts',images_dir => '/images'} })
result = engine.render

NOTE:

Finally I didn't managed to make jruby load sass/compass from a JAR so there's NO need to create an uber-jar that contains jruby-complete and sass/compass (step 2 in my question)

The only change in the ruby-script to run sass/compass from a JAR is:

sassGemDir = 'classpath:/gems/sass-3.2.13/lib'
compassGemDir = 'classpath/compass-0.12.2/lib'
chunkyPngGemDir = 'classpath/gems/chunky_png-1.2.9/lib'
fssmGemDir = 'classpath/gems/fssm-0.2.10/lib'

BUT when I run sass/compass loading from the uber-jar I got two errors:

  1. compass's sprite-importer.rb failed to load sprite_importer.erb file since it was loaded like:

    TEMPLATE_FOLDER = File.join(File.expand_path('../', __FILE__), 'sprite_importer')
    

    so I changed sprite-importer.rb to:

    TEMPLATE_FOLDER = File.join( File.expand_path(File.join(File.dirname(__FILE__))),'sprite_importer')
    

    and this problem went away

  2. compass's frameworks.rb failed to load the frameworks dir: jruby cannot load a dir's contents when the dir is inside a JAR (I susspect it's an error with java 6 or jrockit, which is the JDK I use in weblogic 10.3.6)

    I could not find a solution for this problem so I switched to load sass/compass to be loaded directly from the filesystem and NOT from a JAR file

FINAL NOTE All the problems with the GEMs LOAD_PATH and compass being loaded from within a JAR were NOT an issue when running inside TOMCAT under Java 7

Hope this helps someone who's trying to run sass/compass using an embeded jruby

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top