All | Personal | Sun
« Previous month (Jan 2008) | Main | Next month (Mar 2008) »
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]

Calendar

RSS Feeds

Search

Links

Navigation

Referers