Monday, November 17, 2008

Mac(OSX) Jruby and Rails 2.2

Not Sure why but I wanted to try JRuby and Rails(2.2) new threads...

These are the steps I used to get a application on my mac running with Rails 2.2 and JRuby 1.1.3(I used ports to install JRuby thats why 1.1.3).

Here are the steps:

- First Install JRuby .. # sudo port install jruby

- Fix an annoying warning .. # sudo jruby -S gem install jruby-openssl

- Install rails .. # sudo jruby -S gem install rails

- Install the database connector .. # sudo jruby -S gem install activerecord-jdbc-adapter
  • We Also need to download the mysql java (JDBC) driver
  • Copy mysql-connector-java-x.x.x-bin.jar to $JRUBY_HOME/lib. (/opt/local/share/java/jruby)
  • http://dev.mysql.com/downloads/connector/j/5.1.html

- Upgrade the gem environment .. # sudo jruby -S gem update

- Install latest RubyGems (Rails 2.2 Needs 1.3.1 or higher.. ) .. # sudo jruby -S gem install rubygems-update

- Now you have to force install the update .. # sudo jruby -S update_rubygems

- Install Rails 2.2.1 .. # jruby -S gem install rails -s http://gems.rubyonrails.org

# jruby -S rails myapp
# cd myapp
# vi config/database.yml
  development:
adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/testapp_development
username: root
password:
# vi config/environment.rb
Add this code:

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
if RUBY_PLATFORM =~ /java/
require 'rubygems'
RAILS_CONNECTION_ADAPTERS = %w(jdbc)
end
# jruby script/server
=> Booting WEBrick...
=> Rails 2.2.1 application started on http://0.0.0.0:4000
=> Ctrl-C to shutdown server; call with --help for options
[2008-11-17 16:40:34] INFO WEBrick 1.3.1
[2008-11-17 16:40:34] INFO ruby 1.8.6 (2008-11-17) [java]
[2008-11-17 16:40:34] INFO WEBrick::HTTPServer#start: pid=13484 port=4000


DONE!

No comments: