Robert Dempsey has written a pretty solid little tutorial on deploying your first JRuby on Rails app with Glassfish. It’s powerful stuff. Go read it now, damnit!
The process can still be a bit tricky the first time, especially if you have additional gem dependencies, etc. But once you get it running you’ll be blown away by how simple it is to create a .war and deploy it to any of numerous pre-existing Java application servers (Glassfish).
I had a few issues initially (particularly with openssl support), so I figured I’d document them as an addenum to Robert’s tutorial in case you’re interested. Read on to see my notes…
- Make sure to set JRUBY_HOME in your environment. It’s used by Goldspike.
- If both ruby and jruby are in your path, you can specify the ‘version’ of rake to use by doing: jruby -S rake. This will run the specific command in the JRUBY_HOME/bin directory.
- Edit the goldspike lib/war_config.rb and change the line that reference jruby-complete version 0.99 to read:
add_java_library(maven_library ('org.jruby', 'jruby-complete', '1.0'))
- This will look for JRuby 1.0 instead of 0.9.9. As of this writing you’ll also have to manually retrieve jruby-complete-1.0.jar as the remote sources don’t seem to have it yet. Put it in JRUBY_HOME/lib.
- I happen to be using SSL in my app, so I had to gem install it into the JRuby environment using jruby -S gem install jruby-openssl Make sure the gem ends up in your JRUBY_HOME/lib/ruby/gems hierarchy. Tell goldspike it needs to add this gem with the following line: add_gem(‘jruby-openssl’)
- If you’re doing the jruby-openssl thing you’ll also have to retrieve the latest version of the Bouncy Castle Crypto APIs package for whatever version of Java you’re using (I’m on OS X, Java 1.5). Put this in your JRUBY_HOME/lib directory and then add the library to your war_config.rb file:
add_java_library(maven_library('bouncycastle', 'bcprov-jdk15', '136'))
- Make sure to copy jdbc_databases.rake from ActiveRecord-JDBC to your lib/tasks directory (for ActiveRecord-related rake tasks). Thanks to Ola Bini for pointing me in the right direction there.
- Include the following in environment.rb:
if RUBY_PLATFORM =~ /java/ require 'rubygems' RAILS_CONNECTION_ADAPTERS = %w(jdbc) end