JRuby on Rails on SAP NetWeaver Studio

Many of you have already heard about JRuby and its Rails implementation called JRuby on Rails, for those who do not I would recommend to read the following articles:

  • JRuby: The power of Java and Ruby
  • This article which clearly explain the basics is about JRuby.
  • This article from Java World gives an overview JRuby on Rails. 
  • Additionally, there is another article from Developer.com which runs over the first steps on creating and deploying a JRuby on Rails application.

Ok, once we are all on the same page, I am going to make a more detailed overview, on how to develop a JRuby on Rails project using SAP NetWeaver Studio. Just to mention that I am currently using version 7.1 SP6 which is built over Eclipse 3.3.0 and Java 5 Sdk.  I know it is a little bit more advanced than the most mayority of current SAP projects, which are probably using SAP NetWeaver Studio 7.0 but well, it is what I have.

There is an existing one-click installer from JRuby on Rails suitable for testing for a company called bitnami, which has a very interesting market proposition. I am myself I use RubyStack with no futher problems.
However, I have done manually to fully understand the development architecture. So let se which are the steps to perform:

1) Download JRuby: As first step, we are going to download latest version of JRuby from JRuby site. In this case is JRuby 1.1.4, which can be download from its repositories. Select what it suits for your operating system.

While you wait it to download, if you like you can read something or you want watch a video related to JRuby on Rails, plese the following video:

Ok, now it is already download, we have to find the file and unzip. Do not underestimate the time it takes to find the file wherever you have download it. 🙂 .

As I always install my Jvm on the root directory of my C: drive (c:\jdk15,c:\jdk16,..) . I am going to follow the same procedure again, as it will ease the procedure of adding it to my PATH route. I do not know you but I am a little tired of adding things to my PATH, that I am not going to use so I have created a .bat file which do this for me. For more details about how to getting started. Obviously, it is designed to support my best practices, but you know today is “Convention over configuration” or DIY.


JRuby 1.1.3 or higher
Java 5 or higher
Rails 2.0 or higher

 Install Rails Framework ‘gems install rails -y’ (if behind a http proxy, set HTTP_PROXY=http://${http-proxy-host}:${http-proxy-port}/)
4. Install activerecord-jdbc ‘gems install activerecord-jdbc’
5. Install database/jdbc driver (for mysql http://mysql.com/)
6. Generate your Ruby on Rails application (http://rubyonrails.org/)
7. Modify database.yaml
           adapter: jdbc
           driver: com.mysql.jdbc.Driver (for mysql)
           url: jdbc:mysql://${database-hostname}/${db-schema}
           username: ${username}
           password: ${password}

8. Modify environment.rb by adding
       require ‘active_record/connection_adapters/jdbc_adapter’

9. Download rails-integration-${version}-SNAPSHOT.jar into the WEB-INF/lib by checking out and building the rails-integration project
10. Modify the template web.xml(see references below) with the right value of jruby.home
11. Create a WEB-INF directory in the RoR application directory
12. Copy web.xml to WEB-INF and rails-integration-${version}-SNAPSHOT.jar under WEB-INF/lib
13. Jar up the RoR application directory contents as a WAR file

Requests to appropriate context-root of the deployed web application should invoke your Ruby code !

If you’d like to automate the building of a war file:
Edit rails-integration/build.xml and add the following XML snippet
  <property environment=”env”/>
  <target name=”build-rails-war” depends=”jar”>
    <delete file=”${rails-app-dir}/${rails-app-name}.war”/>
    <mkdir dir=”${rails-app-dir}/WEB-INF/lib”/>
    <copy todir=”${rails-app-dir}/WEB-INF/lib”>
      <fileset file=”${maven.build.directory}/${maven.build.final.name}.jar”/>
      <fileset file=”${maven.repo.local}/org/jruby/jruby/0.9.1/jruby-0.9.1.jar”/>
      <fileset file=”${maven.repo.local}/asm/asm/2.2.2/asm-2.2.2.jar”/>
      <fileset file=”${maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar”/>
    <copy todir=”${rails-app-dir}/WEB-INF/”>
      <fileset file=”samples/scaffold/WEB-INF/web.xml”/>
    <replace file=”${rails-app-dir}/WEB-INF/web.xml” token=”/usr/local/jruby” value=”${env.JRUBY_HOME}”/>
    <jar jarfile=”${rails-app-dir}/${rails-app-name}.war” basedir=”${rails-app-dir}”/>
Make sure JRUBY_HOME is set and run
‘ant -Drails-app-dir=${ror-app-dir} -Drails-app-name=${war-file-name} build-rails-war’
${ror-app-dir}/${ror-app-name}.war should be ready for deployment !

jruby -S gem install -y rails warbler

$JRUBY_HOME/bin/gem install activerecord-jdbc-adapter -y

modify database.yml

adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/blabla_development
username: root
password: root

Modify environment.rb

require File.join(File.dirname(__FILE__), 'boot')
if RUBY_PLATFORM =~ /java/
require 'rubygems'
I would recommend to read of The empty Way
JRuby entries on WordPress

Rails::Initializer.run do |config|

This article is based on the following references:

Kind regards