Jruby And Rails Gets Warbled

Deploying your jruby on rails app to tomcat using warbler.

Earth Date 07/15/2010

Posted by Rich Wheadon | Permalink




I just went through migration of a little concept app on my local machine that has become a piece of our helpdesk business process. The app is a jruby on rails venture that uses ExtJS for the front end.



There were a number of problems I had trying to roll out the code because I failed to get my environment.rb file set up correctly and because I forgot to use “jruby -S” more often in my command line operations. Another set of issues revolved around the fact that a jruby/rails app is better at validation through tomcat than my mongrel local instance, which meant that some of my lesser (or should I say unused) entities were a syntactical mess and the blasted app kept crashing on tomcat. Just like anyone reading this doc would do I just Googled until sane solutions became visible.



As a hit list I offer just a few things that helped me make progress. For reference sake I did all of my work on the Mac OSX 10.6.4 and CentOS. Technologies with meaningful visibility in my coverage are Gems, Ruby, JRuby, Rails, ActiveRecord, Warbler and Tomcat. I’m going to assume Ruby, Gems, Jruby, rails, activerecord-jdbc-adapter, and warbler are already installed and functional. I will , though, again encourage you to make sure all the necessary gems have been installed with “jruby -S gem …”



If it helps, here’s what i have:



richs-imac:myproject rwheadon$jruby -S gem list
*** LOCAL GEMS ***

actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activerecord-jdbc-adapter (0.9.7)
activeresource (2.3.8)
activesupport (2.3.8)
bouncy-castle-java (1.5.0145.2)
columnize (0.3.1)
jruby-jars (1.5.1)
jruby-openssl (0.7.1, 0.7)
jruby-rack (1.0.2)
rack (1.2.1, 1.1.0)
rails (2.3.8)
rake (0.8.7)
rdoc (2.5.9)
rdoc-data (2.5.3)
rspec (1.3.0)
ruby-debug (0.10.3)
ruby-debug-base (0.10.3.2)
rubyzip (0.9.4)
sources (0.0.1)
warbler (1.1.0)


add any of the necessary gems to your environment.rb:



# Specify gems that this application depends on.
# They can then be installed with "rake gems:install"
# on new installations.
# You have to specify the :lib option for libraries
# where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3)
# config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"
config.gem "activerecord-jdbc-adapter", :lib => "active_record/connection_adapters/jdbc_adapter"

Any resource paths you had been testing in mongrel/webrick that went to the webserver root will likely be broken. In reality that shouldn’t have been necessary anyway. instead of



<script type="text/javascript" src="/javascripts/whatever.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="/stylesheets/whatever.css" />


use



<script type="text/javascript" src="javascripts/whatever.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="stylesheets/whatever.css" />


I think the latter will still work in mongrel/webrick anyway. (it did for me.)



goto the root of your project and warble it:



richs-imac:myproject rwheadon$ jruby -S warble war
rm -f myproject.war
Creating myproject.war


A war file will be created in the root and you can then deploy.



richs-imac:myproject rwheadon$ ll
10619 May 20 09:18 README
307 May 20 09:18 Rakefile/
204 May 20 09:18 app/
340 Aug 4 08:19 config/
102 May 20 09:18 doc/
136 May 20 09:18 log/
42464795 Aug 4 11:30 myproject.war
544 Jul 20 09:57 public/
408 May 20 09:18 script/
238 May 20 09:18 test/
204 Jun 7 09:31 tmp/


The war’s project structure will be more like this:



  952 Aug  4 11:30 404.html
930 Aug 4 11:30 422.html
1112 Aug 4 11:30 500.html
528 Aug 4 11:30 dispatch.cgi
909 Aug 4 11:30 dispatch.fcgi
528 Aug 4 11:30 dispatch.rb
1150 Aug 4 11:30 favicon.ico
6438 Aug 4 11:30 favicon.png
4096 Aug 4 11:42 images/
4096 Aug 4 11:42 javascripts
4096 Aug 4 11:42 META-INF/
7385 Aug 4 11:30 rails-index.html
204 Aug 4 11:30 robots.txt
4096 Aug 4 11:42 stylesheets/
4 Aug 4 11:42 WEB-INF/


Don’t forget to set up an apache virtual host if you are using that feature ;)