JRuby and the Glassfish Gem
The glassfish gem is another way to run a rails application in jruby. Before glassfish, I was using jruby script/server.
Using glassfish is simple. Install the gem and run jruby -S glassfish. However, I got a “missing gem” error.
$ sudo jgem install glassfish Successfully installed glassfish-1.0.2-universal-java 1 gem installed $ jruby -S glassfish Starting GlassFish server at: 0.0.0.0:3000 in development environment... Writing log messages to: /Users/crigor/labs/log/development.log. Press Ctrl+C to stop. Missing the Rails 2.3.4 gem. Please `gem install -v=2.3.4 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
rails 2.3.4 is installed. In fact, jruby script/server works
$ jruby script/server => Booting Mongrel => Rails 2.3.4 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server
I checked log/development.log and found an error on the run method on config/boot.rb.
INFO: JRuby version is: 1.4.0 Feb 21, 2010 8:45:12 PM com.sun.grizzly.jruby.rack.RackApplicationPoolFactory getRackApplocationPool SEVERE: exit from /Users/crigor/admoolabs/labs/config/boot.rb:38:in `run' from /Users/crigor/admoolabs/labs/config/boot.rb:11:in `boot!' from /Users/crigor/admoolabs/labs/config/boot.rb:110 from /Users/crigor/admoolabs/labs/config/boot.rb:31:in `require' from /opt/local/share/java/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /Users/crigor/admoolabs/labs/config/environment.rb:7 from /Users/crigor/admoolabs/labs/config/environment.rb:31:in `require' from /opt/local/share/java/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:98:in `load_application' from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:75:in `initialize' from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/jruby/rack/rails.rb:25:in `new' from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/jruby/rack/rails.rb:25:in `new' from <script>:1
gem ‘rails’, version raised an error, thus the message “Missing the Rails 2.3.4 gem”. I’m sure that the gem is installed and jruby script/server works, so I inspected the error.
can't activate rack (~> 1.0.0, runtime) for ["actionpack-2.3.4", "rails-2.3.4"], already activated rack-1.1.0 for ["glassfish-1.0.2-universal-java"]
Look at that, it’s the familiar rubygems dependency problem. glassfish requires rack >= 0.4.0 but rubygems will activate the newest gem available which is version 1.1.0. rails 2.3.4 requires rack ~> 1.0.0, thus the conflict. This is the problem that bundler is trying to solve. Check my other post or the bundler readme for more details on the dependency problem.
The easiest way to get glassfish running is by removing rack 1.1.0. I’m not using it anyway.
$ sudo jgem uninstall rack Select gem to uninstall: 1. rack-1.0.1 2. rack-1.1.0 3. All versions > 2 Successfully uninstalled rack-1.1.0 $ jruby -S glassfish Starting GlassFish server at: 0.0.0.0:3000 in development environment... Writing log messages to: /Users/crigor/admoolabs/labs/log/development.log. Press Ctrl+C to stop.
Go to localhost:3000, click “About your application’s environment” and check development.log
Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0 INFO: Processing Rails::InfoController#properties (for 0:0:0:0:0:0:0:1%0 at 2010-02-21 21:03:38) [GET] Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0 INFO: SQL (28.0ms) SELECT version FROM schema_migrations Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0 INFO: Completed in 302ms (View: 57, DB: 28) | 200 OK [http://localhost/rails/info/properties]
In the future, I will try bundler or loading the gems myself. I already tried this before with ruby 1.8.7 when rails 2.3.5 wasn’t working with bundler 0.9.4.
Please share in the comments if you have other ways of running your jruby apps. Are you using glassfish or a different java app server?