jruby/jruby-rack

Run from source?

viphe opened this issue · 5 comments

Hi,
Is it possible to use a Java webapp container and jruby-rack to run a rails app from the source as opposed to packaging the whole thing with warbler?

yes, it is possible with jetty, tomcat and wildfly

see for starting point: https://github.com/mkristian/hellowarld/blob/wildfly/Mavenfile

Thanks!
Do you know how much of that relies on the Maven plugins or I could, in theory, reproduce the same easily in a case where Jetty is embedded (in my case, in an OSGi container)?

they are actually two asnwers:
embedded jetty should work easily if everything is on the filesystem, like the example I sent. in the end the maven-plugin just uses embedded jetty.

the OSGi container could be different story. if you want to "unzip" the rails application that could work. running everything from an OSGi classloader you might have to wait for jruby-1.7.19 there you can use the new classpath layout from jruby-rack: https://github.com/jruby/jruby/blob/jruby-1_7/maven/jruby/src/it/j2ee_jetty_rack/public/WEB-INF/web.xml where everything gets loaded through the context-classloader.

I would say: yes possible or at least very close - happy to help and improve jruby for such cases ;)

Thanks, this is helpful. It seems I will have to dig deeper.

I achieved this in a POC by creating a host Rails app, whose loading env vars (GEMS, rails root path, etc) are overridden at run time.
This required the addition of a new app layout to jruby-rack though:

    class RoRoJettyLayout < JRuby::Rack::WebInfLayout

      def app_path
        @app_path ||= app_uri
      end

      def app_uri
        @app_uri ||=
          ENV['APP_PATH'] ||
          ENV['RAILS_ROOT']
        raise "APP_PATH or RAILS_ROOT need to be defined" unless @app_uri
        @app_uri
      end

      def real_path(uri)
        uri
      end

    end

Which is then referenced in WEB-INF/web.xml (via config/warbler.rb):

  config.webxml.jruby.rack.layout_class = 'JRuby::Rack::RoRoJettyLayout'