debiancdn

AWS, Content Delivery Network and Debian

日別アーカイブ: 2009/08/18

JRubyでこの先生きのこるには 

donrailsをJRuby対応したのでその顛末をまとめておく.まあ先日のエントリのときの作業なのだが


準備

なくてもいいかもしれないが,JRubyに対応したgemsはgithubにあることが多い.

$ sudo jgem sources -a http://gems.github.com
Password:
http://gems.github.com added to sources


DBまわり

http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/参照.

activerecord-jdbcmysql-adapterをgemでいれた.


gemの追加まわり

pocket-0.1.15は問題なし.

actionwebservice-2.3.2はないようだ.なんと

$ sudo jgem install actionwebserviceSuccessfully installed activesupport-1.4.4
Successfully installed actionpack-1.13.6
Successfully installed activerecord-1.15.6
Successfully installed actionwebservice-1.2.6

という具合.これは手をうたねばならぬ.

/Users/yaar/tmp/actionwebservice/actionwebservice-2.3.2.gem

を発見.

cfardm-2:~/tmp/actionwebservice-2.3.3$ jgem build actionwebservice.gemspec 
  Successfully built RubyGem
  Name: actionwebservice
  Version: 2.3.3
  File: actionwebservice-2.3.3.gem
cfardm-2:~/tmp/actionwebservice-2.3.3$ sudo jgem install actionwebservice-2.3.3.gem 
Successfully installed actionwebservice-2.3.3
1 gem installed

なんとか jruby script/server にこぎつける.

Missing these required gems:
  hpricot  
  will_paginate  
  libxml-ruby  
  libxml-xmlrpc  
You're running:
  ruby 1.8.6.287 at /opt/local/share/java/jruby/bin/jruby
  rubygems 1.3.5 at /opt/local/share/java/jruby/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
cfardm-2:~/playground/donrails$ jrake gems:install

しかし will_paginateがないといわれる.しょうがないので手でインストール.コレハok.

 $ sudo jgem install hpricot libxml-ruby libxml-xmlrpc

すると

ERROR:  Error installing hpricot:
	ERROR: Failed to build gem native extension.

でおわってしまう.libxml-rubyもlibxml-xmlrpcもhpricotもnative extensionをつかってるのでjrubyでは使えない.

hpricot

http://blog.s21g.com/articles/1414 を見るとhpricotは現在JRubyでも使えるようになっているらしい.

 git clone git://github.com/olabini/hpricot.git

してから jrake package_jrubyをすればよさそう.

$ jrake package_jruby
(in /Users/yaar/playground/ruby/hpricot)
/bin/sh: ragel: command not found
Using ragel version: 0.0, location: 
Ragel 6.1 or greater is required.

ragelが必要らしいので portsでいれる.

libxml-ruby

これはlibxml-jrubyにいれかえる方向で.

$ git clone git://github.com/dylanvaughn/libxml-jruby.git 
$ cd libxml-jruby
$ jgem build libxml-jruby.gemspec 
WARNING:  no description specified
  Successfully built RubyGem
  Name: libxml-jruby
  Version: 1.0.0
  File: libxml-jruby-1.0.0-java.gem

あるいは

 jruby -S gem install dylanvaughn-libxml-jruby --source=http://gems.github.com

たぶんソース本体はそのままでいいとおもわれる.

libxml-xmlrpc

jrubyだといらない? なんか最初のに含まれてる?

/opt/local/share/java/jruby/lib/ruby/1.8/xmlrpc/client.rb

will_paginate (XXX)

will_paginate-2.2.2は古い?

    app/helpers/application_helper.rb:426:in `display_article_attachments'
    /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/will_paginate-2.2.2/lib/w
ill_paginate/finder.rb:164:in `method_missing_with_paginate'

などというのを返す.

  • どうもwill_paginateはもう古く,githubにあるmislav-will_paginateをつかうべきのようだ.

http://wiki.github.com/mislav/will_paginate

sudo gem sources -a http://gems.github.com
sudo gem install mislav-will_paginate

enviroment.rbのwill_paginateのところを変更.requireは変更なし.

config.gem "mislav-will_paginate", :lib=>"will_paginate"

しかし問題が.

    app/helpers/application_helper.rb:426:in `display_article_attachments'
    /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.
11/lib/will_paginate/finder.rb:168:in `method_missing_with_paginate'
    /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.
11/lib/will_paginate/finder.rb:168:in `method_missing_with_paginate'
    app/helpers/application_helper.rb:425:in `display_article_attachments'


rd/rdfmtとrd/rd2html-libをどうするべきか

require "rd/rdfmt" してるライブラリをJRubyで動かすスマートな方法がわからん.

結局rb-rdtoolをinstallした.(gemではなく普通にruby setup.rb)