Starting on version 1.13 Mentawai fully supports JRuby. You are able to write your actions in Ruby (or your whole application) or you can call any Ruby code from your Mentawai web application.
To support plain Ruby, all you need to do is copy the jruby.jar file inside the /WEB-INF/lib directory of your Mentawai web application. However, if you plan to use RubyGems and the Ruby Native Libraries (like 'date' for example) you will need to install JRuby in the machine running your Tomcat web server. To install JRuby is very easy. Follow the steps below:
Extract everything inside your root directory (or any directory)
Set the environment variable JRUBY_HOME. (Ex: JRUBY_HOME=c:\jruby-1.1.1)
Set the environment variable JRUBY_OPTS to -rubygems so that you don't need to require 'rubygems' in your code.
Change your PATH environment variable to include %JRUBY_HOME\bin so that you can call the jruby script from anywhere in your shell.
If you did the above steps correctly, you should be able to play with jruby in your shell. Check the examplew below:
Now let's check an example of how to run Ruby inside your Mentawai web application. (download Mentawai 1.13 here if you need to)
All your ruby code must be placed inside the /WEB-INF/ruby/ directory of your web application. Mentawai loads (do the require) any Ruby file from this directory plus it will reload any modified file pretty much like a JSP.
An action written in Ruby: /WEB-INF/ruby/action_test.rb
A Java Action calling Ruby code: /WEB-INF/src/org/hello/action/Hello.java
Ruby code which is called by the Java action above: /WEB-INF/ruby/users_test.rb
Below we have a simple tutorial for the features of the Mentawai integration with JRuby
Simple API to call ruby methods on any Ruby object from Java
JRubyWrapper for making ruby method calls even easier
Support method chaining. Ex: "methods.sort.grep"
Auto-reload any ruby file from the loadpath
Load any ruby file from the classpath with the loadFromClasspath method
Get a singleton instance of the JRubyInterpreter anywhere in your code with the JRubyInterpreter.getInstance() method
Support all JRuby environment variables and provide defaults for them. Ex: JRUBY_OPTS for -rubygems and -Ku , JRUBY_SHELL, JRUBY_SCRIPT, JRUBY_LIB and JRUBY_HOME.
Windows and Linux support
The file foo.rb anywhere in your loadpath (Ruby equivalent of Java's classpath)
OBS: Don't forget to change this file to see how it will be automatically reloaded by JRubyInterpreter.