Rails app with JRuby not working

2019-08-31 03:45发布

问题:

I have an Rails app which was created on Ubuntu. I wanted to run it on a Mac, but after installing bundles and running rails s, I get following errors:

LoadError: load error: sqlite3/sqlite3_native -- java.lang.UnsatisfiedLinkError: failed to load shim library, error: dlopen(/Users/home/.rvm/rubies/jruby-1.7.4/lib/native/Darwin/libjruby-cext.dylib, 10): image not found require at org/jruby/RubyKernel.java:1054
(root) at /Users/home/.rvm/gems/jruby-1.7.4/gems/sqlite3-1.3.8/lib/sqlite3.rb:6 require at org/jruby/RubyKernel.java:1054 (root) at /Users/home/.rvm/gems/jruby-1.7.4@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:1 each at org/jruby/RubyArray.java:1617 require at /Users/home/.rvm/gems/jruby-1.7.4@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72 each at org/jruby/RubyArray.java:1617 require at /Users/home/.rvm/gems/jruby-1.7.4@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70 require at /Users/home/.rvm/gems/jruby-1.7.4@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59 require at /Users/home/.rvm/gems/jruby-1.7.4@global/gems/bundler-1.3.5/lib/bundler.rb:132 require at org/jruby/RubyKernel.java:1054 (root) at /Users/home/workSpace/RubyOnRails/sample_app/config/application.rb:13 tap at org/jruby/RubyKernel.java:1860 (root) at /Users/home/.rvm/gems/jruby-1.7.4/gems/railties-3.2.8/lib/rails/commands.rb:1 require at org/jruby/RubyKernel.java:1054 (root) at script/rails:6

My Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.8'

gem 'sqlite3'

group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1'

gem 'uglifier', '>= 1.0.3' end

gem 'jquery-rails'

gem 'execjs'

group :test, :development do gem "rspec-rails", "~> 2.0" end

gem 'spork'

gem 'webrat'

gem 'heroku'

I am using jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_15-b03 [darwin-x86_64] and Rails 3.2.8

回答1:

The problem stems from the fact that you are trying to use a Ruby gem that relies on a C extension. From the JRuby wiki:

JRuby versions prior to 1.6 did not support Ruby C extensions, and even in 1.6 the support is still "in development" and considered experimental. As of 1.7, it has been disabled and will likely be removed.

Specifically, the error message states: dlopen(/Users/home/.rvm/rubies/jruby-1.7.4/lib/native/Darwin/libjruby-cext.dylib, 10): image not found. This is attempting to load the JRuby C extension wrapper, which is not found. I'm not sure of the exact cause here, but perhaps it didn't get installed.

As I see it, you have two main options:

  1. Install regular MRI instead of JRuby, as you had on Ubuntu. Then you can use gems with C extensions as you wish.
  2. From the same wiki: Use activerecord-jdbc-adapter instead along with jdbc-sqlite3. This will allow you to use JRuby, if you need it for your application.


回答2:

JRuby 1.7.x no longer supports ruby C extensions. See this Jira ticket