Equality: 4 times the charm
{Thursday, August 9th, 2007}Ruby’s equality options have baffled me in recent times. No surprise that JRuby has encountered related problems.
Ruby’s equality options have baffled me in recent times. No surprise that JRuby has encountered related problems.
Want to deploy a Rails app WAR on an application server and confused how to go about it? In this blog I’ll summarise how you can create a WAR. This information is ‘out there’ but so disjointed you’ll rightly give-up before you try, to make matters worse it’s usually specific to GlassFish.
Here I’ll focus on deploying to Tomcat using Java 5.
In my case I checked out the trunk although using 0.9.2 may be an option. Note that you’ll need to perform a couple of modifications if you intend on using JRuby as a substitute for Ruby:
If you need to create the JRuby jar, ant jar constructs jruby.jar in the lib directory.
I had an issue successfully executing the tests, the ANT jar provided in the lib directory appeared to be incorrect (org.apache.tools.ant.util.FileUtils.close(Writer) was not found). Replacing this jar with the latest solved the problem.
Rails-Integration is part of the JRuby Extras project. Unfortunately, it hasn’t been released yet so you’ve no alternative but to grab the package off the trunk.
Rails-Integration has two key parts:
You’ll need to use ANT to JAR-up those servlets: ant jar should do the trick.
Note that the jar task causes tests to execute which will probably initially fail and kill JAR creation. You’ve a few options here:
I ended up taking the latter option to ensure that my snapshot was legitimate. After tweaking with library dependencies I managed to get green lights here.
if RUBY_PLATFORM =~ /java/
require 'rubygems'
RAILS_CONNECTION_ADAPTERS = %w(jdbc)
end
adapter: jdbc driver: com.mysql.jdbc.Driver url: jdbc:mysql://<host>/<database> username : <username> password: <password>
As all of this stuff is experimental (some pre-release, all pre-version 1.0) nothing comes easy. You’ve some tweaking to do. The Rails libraries dispatcher.rb can’t be interpreted correctly by JRuby at the time of writing.
I needed to comment out all lines pertaining to breakpoints as the constant BREAKPOINT_SERVER_PORT (a constant unassociated with a module) could not be interpreted. This is not so bad given Breakpoint/Debug Driven Development should be discouraged.
There are 2 packaging strategies for your Rails application:
I preferred the latter as it significantly reduces the WAR’s payload, but the foremost option is reasonable in cases where you’d like to drop the WAR and run.
Here’s the key steps to create the WAR:
If you’ve followed to this point you should have a WAR in your Rails applications root directory. Drop it in your app server and cross your fingers!
Tip: You should also be able to jruby script\server your application to life via WEBrick, this can be useful to iron out configuration issues.
Related information:
JRuby on Rails
Rails on Glassfish
Rails with ActiveRecord JDBC
For organizations developing and deploying Rails apps in house, does the prospect of deploying Rails apps as a WAR give you that much? Consider this…
And what say you Java shops considering adopting Rails, does this capability really effect your decision? Does it make the prospect of learning a new language and a ream of frameworks and plugins any prettier?
For those convinced of the Rails cool-aid (and why shouldn’t you be anyway?!), it’s neat seeing a Rails app run in the snug, familiar confides of Tomcat and alike - even if it does chug along a tad. It certainly brings into perspective the gains of using the JVM as a VM for other languages – those languages inherit its benefits.