views:

317

answers:

2

Is there a way to map *.rb files to be executed under JRuby with the output being sent out to the browser like a CGI? Basically I'm looking for a JRuby CGI servlet.

Ideally, I'd like to define a JRuby servlet in web.xml and then be able to put *.rb files in WEB-INF/ruby and be able to call them via http://servername/contextname/rubyprogram.rb and pass data to the ruby program either by a form post or as part of the URL.

EDIT: I've done more research and found both Sun's project Phobos (which is bundles an entire Ruby install in a WAR file) and JRuby RACK.

Has anyone been able to set up a light and simple install of Rack that does this? Anyone know of an example config that would let me do this?

+1  A: 

I am not that familiar with J2EE but you could write your own Java servlet that takes a Ruby script name as a parameter and executes it using JRuby as a library.

There are examples on the JRuby site on how to run a Ruby script from a Java program.

Vincent Robert
+1  A: 

You should check out Warbler. It's a gem that lets you package up a Ruby application as a WAR file and run it in a servlet container (with a little help from JRuby-Rack).

You should also take a look at the Glassfish gem, which contains a stripped-down version of the Glassfish app server, which makes it a snap to load up a Rack-compatible application and run it in JRuby.

There's a screencast on how to run a JRuby app in Glassfish here: http://netbeans.tv/technologies/First-JRuby-app-in-GlassFish-86/

There are a ton of other resources to be found here: http://kenai.com/projects/jruby/pages/WalkthroughsAndTutorials

Theo