JRuby1.7 / Rails4.1

システムにgemを入れず、bundlerでローカルに、JRuby 1.7 / Rails 4.1の環境を作る。rbenv/rvmは使わない。
Railsが最新の4.2ではなく、4.1にしたのは、activerecord-jdbc-adapterが4.2対応しきれていないため。
tasks to finish 4.2 support · Issue #599 · jruby/activerecord-jdbc-adapter · GitHub

2段階の作業が必要で、1段階目がrails newするための準備で、2段階目がrails new。

まずは1段階目。

\work>mkdir jrubyrails4
\work>cd jrubyrails4
\work\jrubyrails4>jruby -S bundle init
Writing new Gemfile to /work/jrubyrails4/Gemfile

Gemfileができるので、railsの4.1だけ指定。2桁目を固定するには3桁目の0まで書く。

source "https://rubygems.org"

gem "rails", "~> 4.1.0"

bundle install。

\work\jrubyrails4>jruby -S bundle install --path .\vendor\bundle
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies........................
Installing rake 10.4.2
Installing i18n 0.7.0
Installing json 1.8.2
Installing minitest 5.5.1
Installing thread_safe 0.3.4
Installing tzinfo 1.2.2
Installing activesupport 4.1.9
Installing builder 3.2.2
Installing erubis 2.7.0
Installing actionview 4.1.9
Installing rack 1.5.2
Installing rack-test 0.6.3
Installing actionpack 4.1.9
Installing mime-types 2.4.3
Installing mail 2.6.3
Installing actionmailer 4.1.9
Installing activemodel 4.1.9
Installing arel 5.0.1.20140414130214
Installing activerecord 4.1.9
Using bundler 1.6.0
Installing hike 1.2.3
Installing multi_json 1.11.0
Installing thor 0.19.1
Installing railties 4.1.9
Installing tilt 1.4.1
Installing sprockets 2.12.3
Installing sprockets-rails 2.2.4
Installing rails 4.1.9
Your bundle is complete!
It was installed into ./vendor/bundle

\work\jrubyrails4>

これでrails newを打てるようになる。

次に2段階目。

普通にrails newすると、jrubyじゃないところでbundle installが呼ばれている雰囲気だったので、一旦 --skip-bundle して、後で手動再実行。
jruby -S bundle execってめんどくさいけどみんなどうしているんだろう。

\work\jrubyrails4>jruby -S bundle exec rails new sakememo --skip-bundle
io/console not supported; tty will not be manipulated
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.erb
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/secrets.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep

\work\jrubyrails4>cd sakememo

Gemfileが出来ているので、中身を確認。railsが4.1系になっているはず。
TZInfo::DataSourceNotFound: No source of timezone data could be found. の対応のため、末尾に、tzinfoを追加しておく。
https://github.com/tzinfo/tzinfo/wiki/Resolving-TZInfo::DataSourceNotFound-Errors

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.9'
# Use jdbcsqlite3 as the database for Active Record
gem 'activerecord-jdbcsqlite3-adapter'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyrhino'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',                              group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# 追加しておく
gem 'tzinfo-data', platforms: [:jruby]

bundle install(2回目)。

\work\jrubyrails4\sakememo>jruby -S bundle install --path .\vendor\bundle
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies..........................................................
........................
Installing rake 10.4.2
Installing i18n 0.7.0
Installing json 1.8.2
Installing minitest 5.5.1
Installing thread_safe 0.3.4
Installing tzinfo 1.2.2
Installing activesupport 4.1.9
Installing builder 3.2.2
Installing erubis 2.7.0
Installing actionview 4.1.9
Installing rack 1.5.2
Installing rack-test 0.6.3
Installing actionpack 4.1.9
Installing mime-types 2.4.3
Installing mail 2.6.3
Installing actionmailer 4.1.9
Installing activemodel 4.1.9
Installing arel 5.0.1.20140414130214
Installing activerecord 4.1.9
Installing activerecord-jdbc-adapter 1.3.15
Installing jdbc-sqlite3 3.8.7
Installing activerecord-jdbcsqlite3-adapter 1.3.15
Using bundler 1.6.0
Installing coffee-script-source 1.9.1
Installing execjs 2.4.0
Installing coffee-script 2.3.0
Installing thor 0.19.1
Installing railties 4.1.9
Installing coffee-rails 4.0.1
Installing hike 1.2.3
Installing multi_json 1.11.0
Installing jbuilder 2.2.11
Installing jquery-rails 3.1.2
Installing tilt 1.4.1
Installing sprockets 2.12.3
Installing sprockets-rails 2.2.4
Installing rails 4.1.9
Installing rdoc 4.2.0
Installing sass 3.2.19
Installing sass-rails 4.0.5
Installing sdoc 0.4.1
Installing therubyrhino_jar 1.7.4
Installing therubyrhino 2.0.4
Installing turbolinks 2.5.3
Installing uglifier 2.7.1
Installing tzinfo-data 1.2015.1
Your bundle is complete!
It was installed into ./vendor/bundle
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

\work\jrubyrails4\sakememo>

稼働確認

\work\jrubyrails4\sakememo>jruby -S bundle exec rails server
=> Booting WEBrick
=> Rails 4.1.9 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0
.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2015-03-10 03:38:12] INFO  WEBrick 1.3.1
[2015-03-10 03:38:12] INFO  ruby 1.9.3 (2014-02-24) [java]
[2015-03-10 03:38:12] INFO  WEBrick::HTTPServer#start: pid=10328 port=3000

いつものWelcome aboard表示、ruby versionに(java)がついててrails versionが4.1.9ならOK。


できたもの

とりあえずここまで。
https://github.com/satokano/sakememo