All | Personal | Sun
« Running jMaki on Sun... | Main
20080203 Sunday February 03, 2008

Deploying JRuby on Rails WAR on Sun Java System Web Server 7 Update 2 Deploying JRuby on Rails on Web Server 7 Update 2

Deploying JRuby on Rails WAR on Sun Java System Web Server 7 Update 2




Sun Java System Web Server 7 Update 2 (henceforth referred to as WS7U2)  is an industry leader in performance and scalability. It is now easy to deploy JRuby on Rails apps as WAR files on WS7U2.

What is JRuby ?

JRuby is an 100% pure-Java implementation of the Ruby programming language. Ruby, the full-featured object-oriented dynamic (scripting) language, with strong support for functional programming and metaprogramming allows for flexibility and ease of development. JRuby, a JVM-based interpreter for Ruby, combines the ease of the Ruby language with execution in the powerful JVM, including full integration to and from Java libraries.

What is Rails?

Rails speeds and simplifies database backed Web application development. With JRuby, Rails will gain access to the functionality, power, and industry acceptance of Java libraries and the JVM. .

Why JRuby on Rails?

Ruby on Rails  with its ease of development and Java platform with its JVM, libraries and Web Servers are a natural fit to develop enterprise quality applications in an easy and timely manner. This article details  the advantages of JRuby on Rails.

Why Sun Java System Web Server Update 2?

Creating JRuby on Rails WAR file

I used a Sparc, Solaris10 box for my deployment. WS7U2 supports several platforms. You may choose a platform suitable to your application development.
%  cd  /space
% tar xvf /tmp/jruby-bin-1.1RC1.tar
% setenv JRUBY_HOME /space/jruby-1.1RC1
% set path=($JRUBY_HOME/bin $path)
% cd $JRUBY_HOME
%  $JRUBY_HOME/bin/gem install rails -y --no-ri --no-rdoc
%  cd /space
%  tar xvf /tmp/mysql-5.0.51a-solaris10-sparc.tar
%  cd /space
% tar xvf /tmp/mysql-connector-java-5.1.5.tar
% cp /space/mysql-connector-java-5.1.5/mysql-connector-java-5.1.5-bin.jar $JRUBY_HOME/lib
% cd $JRUBY_HOME
% jruby $JRUBY_HOME/bin/rails moviestore
% cd moviestore
development:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/moviestore_development
  username: root


# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/moviestore_test
  username: root
require File.join(File.dirname(__FILE__), 'boot')

if RUBY_PLATFORM =~ /java/
   require 'rubygems'
   RAILS_CONNECTION_ADAPTERS = %w(jdbc)
end

Rails::Initializer.run do |config|
% cd $MYSQL_HOME
% ./configure
% $MYSQL_HOME/bin/mysqladmin -u root create moviestore_development
%  $MYSQL_HOME/bin/mysqladmin -u root create moviestore_test
% cd $JRUBY_HOME/moviestore
% jruby -S gem install activerecord-jdbcmysql-adapter
% jruby $JRUBY_HOME/bin/rake db:create:all
%  jruby script/generate scaffold Movie title:string description:text
% jruby $JRUBY_HOME/bin/rake  db:migrate
(in /space/jruby-1.1RC1/moviestore)
== 1 CreateMovies: migrating ==================================================
-- create_table(:movies)
   -> 0.0530s
   -> 0 rows
== 1 CreateMovies: migrated (0.0550s) =========================================
%  jruby script/plugin install http://jruby-extras.rubyforge.org/svn/trunk/rails-integration/plugins/goldspike
      @java_libraries = {}
      # default java libraries
      add_library(maven_library('org.jruby', 'jruby-complete', '1.0.3'))
      add_library(maven_library('org.jruby.extras', 'goldspike', '1.4'))
      add_library(maven_library('javax.activation', 'activation', '1.1'))
      add_library(maven_library('commons-pool', 'commons-pool', '1.3'))
      add_library(maven_library('bouncycastle', 'bcprov-jdk14', '124'))
      add_library(maven_library ('mysql', 'mysql-connector-java', '5.0.5'))
development:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/moviestore_development
  username: root


# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/moviestore_test
  username: root

production:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/moviestore_development
  username: root

          Run the migration script again for the production
% jruby $JRUBY_HOME/bin/rake  db:migrate RAIL_ENV=production
  # Use the database for sessions instead of the cookie-based default,
  # which shouldn't be used to store highly confidential information
  # (create the session table with 'rake db:sessions:create')
   config.action_controller.session_store = :active_record_store


          change the following line in your app/controllers/application.rb
  
# See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery  :secret => 'f2de6acb89c9437235bfd4f4b9fef1a3
% jruby $JRUBY_HOME/bin/rake war:standalone:create

Deploying WAR file on Sun Java System Web Server 7 Update 2

You can now deploy the WAR generated in the previous section on WS7U2.
% mkdir /space/ws7install
% cd /space/ws7install
% tar xvf /tmp/sjsws-7_0u2-solaris-sparc.tar.gz
% ./setup
% setenv WS /space/webserver7
%  $WS/admin-server/bin/startserv
% $WS/bin/wadm add-webapp
--vs test --config test --user admin --host foobar --port 8989 --password-file /tmp/admin.passwd --uri /moviestore $JRUBY_HOME/moviestore/moviestore.war

          When I installed WS7U2, I gave the password as adminadmin and that is what is in my admin.passwd file

wadm_password=adminadmin
%   $WS/bin/wadm deploy-config --user admin --password-file /tmp/admin.passwd test
Jruby on Rails Application

References

http://edgibbs.com/2007/05/25/deploying-rails-to-tomcat-as-a-war-with-jruby

http://fairleads.blogspot.com/2007/12/rails-20-and-scaffolding-step-by-step.html



Posted by sabada ( Feb 03 2008, 03:56:00 PM PST ) Permalink Comments [3]

Trackback URL: http://blogs.sun.com/sabada/entry/deploying_jruby_on_rails_war
Comments:

Hi all,

I am working for a software integrator company. My projects includes working on Java and Ruby on Rails and Ajax. I think Web Services is really cool. We also recently have to now work on REST and they are talking about mashups and Struts. Can anyone tell me if there are some good training or conferences so that me and my team members can get to speed with these technologies. Learning from books is not my cup of tea, even not when I was doing engineering ;)

All the help that group members can provide in this regard is much appreciated.

Thanks,
Vaibhavi

Posted by Vaibhavi on January 23, 2009 at 11:09 PM PST #

Hi Vaibhavi,

There are several online resources available that you just google for. If any of your team like to read then quality books from wiley and oreilly cover such technologies in detail.

I also highly recommend you could attend the upcoming Great Indian Developer Summit (developersummit dot com) that is covering Java, Agile, REST, JAX-RS, mashups, .NET, Rich Web, JPA, SOA, rich user experiences, Spring, Groovy and more. They have most of the creators of these technologies as speakers. My team is attending this summit 22-25 apr at IISc campus where we are attending the web conference on April 23 and java on April 24. We have been able to get very good discounts. Maybe all those who are interested from your group can sign up together and get a good bargain from them. what say? I also attended last year's conference and had a really cool time.

In Hyderabad there is Sun Tech Days with some sun speakers.

Thanks,
Anaz

Posted by Anaz Amina on January 24, 2009 at 12:04 AM PST #

How about using warbler to package a rails app as a war. I found this to be a simple and way to create the war. And last time I checked goldspike was lagging behind on releases while warbler was current (supports jruby 1.1.6 I believe)

Posted by sud on January 28, 2009 at 06:59 PM PST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed

Calendar

RSS Feeds

Search

Links

Navigation

Referers