rubyglassfishjrubywarblerjruby-rack

Multiple war web applications in ear with JRuby rack


I'm trying to pack two JRuby Sinatra web apps (runtime 1.9) bundled with warbler into an ear file. After deploying in glassfish (2.1.1 or 3.1) I have a crash.

JRuby.jar, jruby-stdlib.jar and jruby-rack.jar are accesible in the classpath of both applications and both of them deploy correctly if I leave only one of them. But if I leave them two the second one always crashes while deploying for an error during rack startup:

[#|2012-07-20T10:00:10.743+0200|INFO|sun-appserver2.1|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=Thread-34;|PWC1412: WebModule[/licences] ServletContext.log():INFO: jruby 1.6.7.2 (ruby-1.9.2-p312) (2012-05-01 26e08ba) (Java HotSpot(TM) Client VM 1.6.0_30) [linux-i386-java]|#]

[#|2012-07-20T10:00:10.744+0200|INFO|sun-appserver2.1|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=Thread-34;|PWC1412: WebModule[/licences] ServletContext.log():INFO: using a shared (threadsafe!) runtime|#]

[#|2012-07-20T10:00:11.926+0200|INFO|sun-appserver2.1|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=Thread-34;|PWC1412: WebModule[/licences] ServletContext.log():An exception happened during JRuby-Rack startup
invalid runtime
--- System
jruby 1.6.7.2 (ruby-1.9.2-p312) (2012-05-01 26e08ba) (Java HotSpot(TM) Client VM 1.6.0_30) [linux-i386-java]
Time: 2012-07-20 10:00:11 +0200
Server: Sun GlassFish Enterprise Server v2.1.1
jruby.home: file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home

--- Context Init Parameters:
com.sun.faces.forceLoadConfiguration = true
com.sun.faces.injectionProvider = com.sun.faces.vendor.GlassFishInjectionProvider
com.sun.faces.validateXml = true
jruby.compat.version = 1.9
public.root = /
rack.env = production

--- Backtrace
RuntimeError: invalid runtime
        require at org/jruby/RubyKernel.java:1042
        require at file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36
            Ext at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:13
           JSON at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:12
         (root) at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:9
        require at org/jruby/RubyKernel.java:1042
        require at file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36
           JSON at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:58
         (root) at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json.rb:54
        require at org/jruby/RubyKernel.java:1042
        require at file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:60
        require at file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55
         (root) at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json.rb:3
        require at org/jruby/RubyKernel.java:1042
        require at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/./lib/licences.rb:36
         (root) at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/config.ru:1
  instance_eval at org/jruby/RubyBasicObject.java:1730
     initialize at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/rack-1.4.1/lib/rack/builder.rb:51
         (root) at /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/config.ru:1

--- RubyGems
Gem.dir: /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems
Gem.path:
/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems
Activated gems:
  rack-1.4.1
  haml-3.1.6
  rack-protection-1.2.0
  tilt-1.3.3
  sinatra-1.3.2
  json-1.7.3

--- Bundler
undefined method `bundle_path' for Bundler:Module

--- JRuby-Rack Config
compat_version = RUBY1_9
default_logger = org.jruby.rack.logging.StandardOutLogger@171c310
err = org.apache.jasper.util.SystemLogHandler@d9b1cd
filter_adds_html = true
filter_verifies_resource = false
ignore_environment = false
initial_memory_buffer_size = 
initial_runtimes = 
jms_connection_factory = 
jms_jndi_properties = 
logger = org.jruby.rack.logging.ServletContextLogger@11196da
logger_class_name = servlet_context
logger_name = jruby.rack
maximum_memory_buffer_size = 
maximum_runtimes = 
num_initializer_threads = 
out = com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingPrintStream@31c0d7
rackup = 
rackup_path = 
rewindable = true
runtime_arguments = 
runtime_timeout_seconds = 
serial_initialization = false
servlet_context = org.apache.catalina.core.ApplicationContextFacade@1033f5a
|#]

[#|2012-07-20T10:00:11.928+0200|SEVERE|sun-appserver2.1|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=Thread-34;_RequestID=bb69f89a-3d4a-46db-9b73-34ab72248271;|WebModule[/licences]ERROR: unable to create shared application instance
org.jruby.rack.RackInitializationException: invalid runtime
 from file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:13:in `Ext'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:12:in `JSON'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:9:in `(root)'
 from org/jruby/RubyKernel.java:1042:in `require'
 from file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json/ext.rb:58:in `JSON'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json.rb:54:in `(root)'
 from org/jruby/RubyKernel.java:1042:in `require'
 from file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:60:in `require'
 from file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `require'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/gems/gems/json-1.7.3/lib/json.rb:3:in `(root)'
 from org/jruby/RubyKernel.java:1042:in `require'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/./lib/licences.rb:36:in `require'
 from /usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/licences-web_war/WEB-INF/config.ru:1:in `(root)'
 from..

Based on the error, it looks like the second application for a reason theat I can't understand is using 1.8 rubygems:

require at file:/usr/local/glassfish/domains/myapp-domain/applications/j2ee-apps/myapp-server/lib/jruby-stdlib.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36

There is no require 'rubygems' in my code or such.

My gemfile.lock is

  remote: http://rubygems.org/
  specs:
    haml (3.1.6)
    jruby-jars (1.6.7.2)
    jruby-rack (1.1.7)
    json (1.7.3)
    mime-types (1.19)
    rack (1.4.1)
    rack-protection (1.2.0)
      rack
    rack-test (0.6.1)
      rack (>= 1.0)
    rake (0.9.2.2)
    rest-client (1.6.7)
      mime-types (>= 1.16)
    rspec-mocks (2.11.1)
    rubyzip (0.9.9)
    sinatra (1.3.2)
      rack (~> 1.3, >= 1.3.6)
      rack-protection (~> 1.2)
      tilt (~> 1.3, >= 1.3.3)
    tilt (1.3.3)
    warbler (1.3.5)
      jruby-jars (>= 1.4.0)
      jruby-rack (>= 1.0.0)
      rake (>= 0.8.7)
      rubyzip (>= 0.9.4)

PLATFORMS
  x86-mingw32

DEPENDENCIES
  haml
  json
  rack-test
  rest-client
  rspec-mocks
  sinatra
  warbler

Thanks a lot in advance.


Solution

  • Looks like by default in glassfish jar files are shared between war applications and looks like jruby-rack does not like being shared all around.

    Some changes in sun-web.xml were needed in my case to isolate classloader

    http://docs.oracle.com/cd/E19316-01/820-4336/beadh/index.html