JRuby onto the Rails on MacOSX

http://rorblog.techcfl.com/2007/06/01/get-jruby-onto-the-rails-on-mac-os-x/
を参考に、Railsをインストールしてみる:

  • jruby 1.1.2 インストール

http://dist.codehaus.org/jruby/jruby-bin-1.1.2.zip

$ sudo unzip jruby-bin-1.1.2.zip -d /usr/local/
  • mysql 5.1 インストール

http://dev.mysql.com/downloads/mysql/5.1.html
Mac OS X (package format) downloads

  • mysql-connector-java 5.1 インストール

http://dev.mysql.com/downloads/connector/j/5.1.html

$ unzip mysql-connector-java-5.1.6.zip
$ cd mysql-connector-java-5.1.6
$ sudo cp mysql-connector-java-5.1.6-bin.jar /usr/local/jruby-1.1.2/lib/
$ cat .bash_profile 
export JRUBY_HOME=/usr/local/jruby-1.1.2
export PATH=$PATH:$JRUBY_HOME/bin
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
$ source .bash_profile 
  • rails インストール
$ sudo jruby -S gem install rails
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed activesupport-2.1.0
Successfully installed activerecord-2.1.0
Successfully installed actionpack-2.1.0
Successfully installed actionmailer-2.1.0
Successfully installed activeresource-2.1.0
Successfully installed rails-2.1.0
6 gems installed
Installing ri documentation for activesupport-2.1.0...
Installing ri documentation for activerecord-2.1.0...
Installing ri documentation for actionpack-2.1.0...
Installing ri documentation for actionmailer-2.1.0...
Installing ri documentation for activeresource-2.1.0...
Installing RDoc documentation for activesupport-2.1.0...
Installing RDoc documentation for activerecord-2.1.0...
Installing RDoc documentation for actionpack-2.1.0...
Installing RDoc documentation for actionmailer-2.1.0...
Installing RDoc documentation for activeresource-2.1.0...
  • rake インストール
$ sudo jruby -S gem install rake     
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed rake-0.8.1
1 gem installed
Installing ri documentation for rake-0.8.1...
Installing RDoc documentation for rake-0.8.1...
$ sudo jruby -S gem install activerecord-jdbc-adapter
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed activerecord-jdbc-adapter-0.8
1 gem installed
Installing ri documentation for activerecord-jdbc-adapter-0.8...
Installing RDoc documentation for activerecord-jdbc-adapter-0.8...
  • Railsアプリtestappを生成
$ jruby -S rails testapp
      create  
      create  app/controllers
      create  app/helpers
      create  app/models
      create  app/views/layouts
      create  config/environments
      create  config/initializers
      create  db
      create  doc
      create  lib
      create  lib/tasks
      create  log
      create  public/images
      create  public/javascripts
      create  public/stylesheets
      create  script/performance
      create  script/process
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/unit
      create  vendor
      create  vendor/plugins
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  Rakefile
      create  README
      create  app/controllers/application.rb
      create  app/helpers/application_helper.rb
      create  test/test_helper.rb
      create  config/database.yml
      create  config/routes.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_rails_defaults.rb
      create  config/boot.rb
      create  config/environment.rb
      create  config/environments/production.rb
      create  config/environments/development.rb
      create  config/environments/test.rb
      create  script/about
      create  script/console
      create  script/dbconsole
      create  script/destroy
      create  script/generate
      create  script/performance/benchmarker
      create  script/performance/profiler
      create  script/performance/request
      create  script/process/reaper
      create  script/process/spawner
      create  script/process/inspector
      create  script/runner
      create  script/server
      create  script/plugin
      create  public/dispatch.rb
      create  public/dispatch.cgi
      create  public/dispatch.fcgi
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/index.html
      create  public/favicon.ico
      create  public/robots.txt
      create  public/images/rails.png
      create  public/javascripts/prototype.js
      create  public/javascripts/effects.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/controls.js
      create  public/javascripts/application.js
      create  doc/README_FOR_APP
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
  • データベースtestapp_developmentを作成
$ mysqladmin -uroot create testapp_development
  • testapp/config/database.ymlを編集
development:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/testapp_development
  username: root
  password:
  • testapp/config/environment.rbを編集
if RUBY_PLATFORM =~ /java/
  require 'rubygems'
  RAILS_CONNECTION_ADAPTERS = %w(jdbc)
end
  • migrationを生成
$ jruby script/generate migration CreateWidgetsTable
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      create  db/migrate
      create  db/migrate/20080601191559_create_widgets_table.rb
  • migrationを実行
$ jruby -S rake db:migrate          
(in /Users/****/jruby/testapp)
== 20080601191559 CreateWidgetsTable: migrating ===============================
== 20080601191559 CreateWidgetsTable: migrated (0.0000s) ======================
  • scaffoldを生成
$ jruby script/generate scaffold widget
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      exists  app/models/
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/widgets
      exists  app/views/layouts/
      exists  test/functional/
      exists  test/unit/
      exists  public/stylesheets/
      create  app/views/widgets/index.html.erb
      create  app/views/widgets/show.html.erb
      create  app/views/widgets/new.html.erb
      create  app/views/widgets/edit.html.erb
      create  app/views/layouts/widgets.html.erb
      create  public/stylesheets/scaffold.css
      create  app/controllers/widgets_controller.rb
      create  test/functional/widgets_controller_test.rb
      create  app/helpers/widgets_helper.rb
       route  map.resources :widgets
  dependency  model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
      create    app/models/widget.rb
      create    test/unit/widget_test.rb
      create    test/fixtures/widgets.yml
      exists    db/migrate
      create    db/migrate/20080601192302_create_widgets.rb
  • migrationを実行
$ jruby -S rake db:migrate
(in /Users/****/jruby/testapp)
== 20080601192302 CreateWidgets: migrating ====================================
-- create_table(:widgets)
   -> 0.0830s
   -> 0 rows
== 20080601192302 CreateWidgets: migrated (0.0840s) ===========================
$ jruby script/server
=> Booting WEBrick...
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
=> Rails 2.1.0 application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2008-06-02 04:24:25] INFO  WEBrick 1.3.1
[2008-06-02 04:24:25] INFO  ruby 1.8.6 (2008-04-22) [java]
[2008-06-02 04:24:25] INFO  WEBrick::HTTPServer#start: pid=1612 port=3000
  • ブラウザで以下のURLにアクセス:

http://localhost:3000/widgets