Plug-in any Ruby/Rack based framework to GlassFish
Here is how you can do it on GlassFish gem:
Insall JRuby
Install JRuby from here. Setup JRUBY_HOME to the install location and add JRUBY_HOME/bin to your PATH.Install GlassFish gem
$ gem install glassfish
Now, lets write a trivial app and save it in file: myapp.rb
class MyAppWrite a rack-up script and save it in myframework.ru
def self.Run
"Hello World"
end
end
require 'rubygems'
gem 'rack'
require 'rack/handler/grizzly'
require 'myapp'
app = proc do |env|
resp = MyApp.Run
[
200, # Status code
{ # Response headers
'Content-Type' => 'text/html',
'Content-Length' => resp.length,
},
[resp] # Response body
]
end
That is pretty much your sample Ruby application and the Rack-up script to run on GlassFish. Above require 'rack/handler/grizzly' makes Grizzly handler available to Rack.
To run it, simply run glassfish in side the directory where myapp.rb and myframework.ru are placed.
% glassfish
Starting GlassFish server at: 192.168.1.103:3000 in development environment...
Writing log messages to: /Users/vivek/dev/foo/log/development.log.
Press Ctrl+C to stop.
Now access, http://localhost:3000 in your browser to access your app.
If you are running GlassFish v3 server and want to deploy this app, you would simply use the same asadmin command from inside the application directory:
$ asadmin deploy .
GlassFish gem as well as GlassFish v3 server can auto-detect Rails,
Merb and Sinatra applications. You can use the above mentioned
technique to plugin other frameworks. For reference also see Jacob's blog
where he explains how Sintra application is plugged in to GlassFish.- Login or register to post comments
- Printer-friendly version
- vivekp's blog
- 2621 reads






Comments
by jamesbritt - 2009-07-19 13:15
I've been tryig to get this working, but it fails right away with this: SEVERE: uninitialized constant Rack::VERSION Any idea why? jruby 1.4.0dev (ruby 1.8.6p287) (2009-07-13 6586) (Java HotSpot(TM) Client VM 1.6.0_07) [i386-java] glassfish (0.9.5), rack (1.0.0)by johnlloydjones - 2009-08-01 10:16
OK, success. I added this line to the .ru file: require 'jruby/rack/grizzly_helper' (Oh and I still need to define Rack::VERSION as above.)by johnlloydjones - 2009-08-01 09:50
OK, maybe not so simple. I added this to the top of my test.rb file: module Rack VERSION = '1.0' end Now I get this: SEVERE: uninitialized constant JRuby::Rack from :1 com.sun.grizzly.jruby.rack.RackInitializationException: uninitialized constant JRuby::Rack from :1 at com.sun.grizzly.jruby.rack.DefaultRackApplicationFactory.createApplication(DefaultRackApplicationFactory.ja va:169) at com.sun.grizzly.jruby.rack.DefaultRackApplicationFactory.newApplication(DefaultRackApplicationFactory.java: 69) Something is missing?by johnlloydjones - 2009-08-01 09:36
I also get the uninitialized constant Rack::VERSION error. As far as I can see, this is because the jruby-rack.jar is not being found. Where should it be placed for the glassfish gem to use it?