Wednesday, November 19, 2008

Deploy Ruby on Rails to JBoss (Tomcat)

Ruby can be run on the JVM as a war file. The Hello World is really very simple following the steps outlined by Arun Gupta.

1. Install jruby.

2. Install rails and JRuby-Jack

kstam-mbpro-2:ruby kstam$ jruby -S gem install rails warbler --no-ri --no-rdoc
JRuby limited openssl loaded. gem install jruby-openssl for full support.
Successfully installed activesupport-2.1.2
Successfully installed activerecord-2.1.2
Successfully installed actionpack-2.1.2
Successfully installed actionmailer-2.1.2
Successfully installed activeresource-2.1.2
Successfully installed rails-2.1.2
Successfully installed warbler-0.9.11
7 gems installed

3. Create a Hello Rails app: jruby -S rails hello -d mysql

4. open hello/config/environment.rb in your favorite editor and uncomment so the line looks like
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

5. Use warble to create your war file
jruby -S warble

6. copy the hello.war to your server/default/deploy directory

7. Hit http://localhost:8080/hello in your browser.

Conclusion: A rails application is basically packaged up in the WEB-INF/ directory of the war and a ruby filter defined in the web.xml takes care of running it.

I also found that in JBoss 5, there would be no need for deploying it in a war, as the the deployer framework of JBoss-Microcontainer enables in-place native deployment of Rails applications in a way familiar to traditional rubyists.

Voices that matter, Professional Ruby Conference

As stated before I'm a Java guy, however this week I'm at a Ruby conference in Boston. I'm working on a 2 year old java based application and we started to do Ruby on Rails right when I got on board. The RoR has been pretty successful, and I have to admit it sure is much, much easier to work with than Struts and jsps. There is still a chance Seam may save Java for the web tier, but for the current project Seam is not an option. So we're working on a hybrid architecture where we can run RoR and Java, so here I am at the Ruby conference! So when I write this review you will now hopefully understand my point of view.

Schedule: November 17-20, 2008.

For me the presentation by Thomas Enebo, Ruby and the Java Virtual Machine was an eye opener. Being new to Ruby in general I didn't not have much understanding on how JRuby worked on the JVM until now. It turns out that although JRuby trails Ruby a bit in terms of releases, it is identical to Ruby, but will have a different sets of bugs ;), however the best part is that JRuby is faster, and it can call into Java natively. It does run your code as byte code, but it stays dynamic! On the flipside this means that it won't ever be as fast as running Java on the JVM. Now the cool part is that you can deploy a RoR application as war file to your appserver, and talk natively to any code written in Java. Currently they are working on to finalize Ruby 1.9 features. This presentation really came to live for me when I went to the 'Lightning Round' later that night, where Mark Menard (from Vita Rara) spoke about his experiences with JRuby. He runs a Spring based application and first tried Groovy on Rails, but in the end he discovered that Groovy meta-model is too close to Java and so he started experimenting with RoR deployed to the JVM, and discovered that it really works as advertised. He is rewriting his application from the ground up and just replaced Hibernate by ActiveRecord, which proves that you can port pieces of your app while being in flight. For me this is very exciting to hear. Not necessarily that Hibernate can be swapped out from ActiveRecord, but more that it is not only possible but that it is actually a practical solution to build hybrid apps by running Ruby on the JVM!

Another talk I really liked was given by Ezra Zygmuntowicz, Four Years of Ruby Deployment. He went over the history of Ruby webservers (Mongrel, Thin, Ebb, NginX, Passenger), and liked Rack as the web equalizer since it abstracts these different implementation, and he picked Thin + NginX as his implementation preference. However then he demoed an application called Nanite, which is a web-based app to configure a linux server, with the possibility of cloning a certain configuration to multiple other nodes.

Oh I almost forgot, everyone seems to run their own little consulting firm writing Rails apps, all the speakers wrote a book and everyone uses Twitter.

It's actually pretty cool as I learn more about it!