本文介绍了将Ruby/Rails/MRI应用程序移植到JRuby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用rbenv,MRI Ruby(1.9.2-p290),rails 3.0.9和SQLite3的Ruby/Rails开发环境.我想将其移植到JRuby,但是这样做除了在Rails应用程序的根目录中运行"rbenv local jruby-1.6.4"和"rails server"之外,无需执行任何其他操作即可使用它与JRuby,"rbenv local 1.9.2-p290"和"rails serer"一起用于MRI Ruby.

I have a Ruby/Rails devvelopment environment using rbenv, MRI Ruby (1.9.2-p290), rails 3.0.9, and SQLite3. I would like to port it to JRuby, but do it such that I don't have to do anything more than run "rbenv local jruby-1.6.4" and "rails server" in the root directory of the Rails application to use it with JRuby, and "rbenv local 1.9.2-p290" and "rails serer" to use it with MRI Ruby.

我知道在Ruby和JRuby中访问SQLite的宝石是不同的,但是如何编写Gemfile以便当Ruby是MRI时拾取与MRI相关的宝石,并选择与JRuby相关的宝石Ruby是JRuby的时候?

I am aware that the gems to access SQLite are different for Ruby versus JRuby, but how do you write the Gemfile such that the MRI-relevant gems are picked up when the Ruby is MRI, and the JRuby-relevant gems are picked up when the Ruby is JRuby?

我还需要将其移植到MySQL而不是SQLite.我需要在Ruby和JRuby中使用哪些宝石?

I will also need to port it to MySQL instead of SQLite. Which gems do I need to use here for Ruby and JRuby?

为便于记录,我使用的是Ubuntu 11.04,Ruby 1.9.2-p290,JRuby 1.6.4和Rails 3.0.9或3.0.10.

For the record, I'm using Ubuntu 11.04, Ruby 1.9.2-p290, JRuby 1.6.4, and Rails 3.0.9 or 3.0.10.

推荐答案

去年,我们将大型Rails应用程序移植到了JRuby,这是一项令人惊讶的工作.当然,它的部分原因与应用程序的编写不当以及具有许多旧代码有关,但仍然如此.如果您想知道:我们的大多数问题都来自我们使用的宝石,那么有时取决于例如当时在JRuby中无法正常使用的FFI.我后来去Rubinius的一个港口似乎没有那么多痛苦,但是为了支持MRI而被放弃了.

We ported a large Rails application to JRuby last year and it was a surprising amount of work. Granted, part of it had to do with the app being rather badly written and having lots of legacy code, but still. In case you wonder: most of our problems came from gems we used, which then sometimes depended on e.g. FFI that didn't properly work with JRuby at that time. A port to Rubinius I did a little later seemed a lot less painful, but was abandoned in favor of staying with MRI.

对于Gemfile,有一个platform选项可以使用.这是Bundler文档中的一个示例:

For the Gemfile, there's a platform option you can use. Here's an example from the Bundler docs:

gem "weakling",   :platforms => :jruby
gem "ruby-debug", :platforms => :mri_18
gem "nokogiri",   :platforms => [:mri_18, :jruby]

它也具有块形式:

platforms :jruby do
  gem "foo"
end

作为MySQL的瑰宝,我将使用恰当地命名为mysql的JRuby.

As a gem for MySQL I'd use the aptly named mysql, there seems to be a jdbc-mysql for JRuby.

这篇关于将Ruby/Rails/MRI应用程序移植到JRuby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:00