Saturday, May 11, 2013

How to Run Rails 4.0.0.rc1 on JRuby

Getting Rails 4.0.0.rc1 running on JRuby isn't that different from running it on MRI, but there are a few minor things you'll need to adjust. Let's start with a new Rails4 app. Make sure you're using JRuby and install the Rails4 release candidate like this:

Then use the rails command to generate a new app.

Move into the newly created my_app directory so we can tweak some settings. Open the Gemfile in an editor and look for these lines:

First, we'll remove jruby-openssl because it's included in JRuby 1.7 (this has been fixed in Rails master). Then we need to set the version of activerecord-jdbcsqlite3-adapter to 1.3.0.beta1.  Next, you should thank Karol Bucek (@kares) for all the hard work he's put into activerecord-jdbc and jruby-rack. Your Gemfile should now have just these lines in in place of the code shown above:

Now return to the console and update bundler like this:

Do some basic housekeeping

Now we can smoke test the app by starting the server like this:

Point a browser to http://localhost:3000 and there's a chance you'll see the app running.  But you might encounter the error shown below:

OpenSSL::Cipher::CipherError: Illegal key size: possibly you need to install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for your JRE

If you see this error it means you need to install the unrestricted policy files for the JVM. You can find these at the Oracle Website. Download the zip file, and extract the two important files it contains: local_policy.jar and US_export_policy.jar. Move these files into your $JAVA_HOME/jre/lib/security directory, and replace the existing files of the same name.  On Mac OS X they are probably located here:


With the unrestricted policy files installed, restart the server and you'll be good to go. But this may present a problem in deployment. For example, you won't be able to update the JVM on a Heroku dyno. Another option may be to downgrade cryptography as described in this JIRA issue, but I haven't tried that. Hopefully this will all get worked out.

And of course, you probably won't want to use WEBrick in production. Warbler 1.3.8 may work for you, but try the rails4 branch if it doesn't.  I have an example of a working Rails4 app on BitBucket in my warbler-examples repo.

I haven't attempted to run a Rails4 app on Trinidad, Puma or TorqueBox. I would love to hear your results.

Please give this a go, and report back with any problems you find.  We would love to have Rails4 working on JRuby the day it's released.


  1. Thanks for this, we have a large Rails 3.1 app running on Jruby 1.6.7, we'll give 4.0.0rc1 a spin w/ Jruby 1.7.3

  2. Thanks for this, but the illegal key size error is a big deal for anyone that doesn't have the ability to add that .jar file to their production environment, plus it's an external dependencies that is bound to be missed about when migrating or updating a server.

    Do you have any idea how to actually lower the key size to 128 bits instead of 256? It's not clear how to do that for a rails app from the JIRA ticket.

  3. Yes Simon, that's very true. I haven't tried it yet myself. I would be very curious to hear if and how others got it working with the smaller key size.

  4. I replaced JCE jars as suggested,

    I'm seeing the following when using fog that depends on excon

    problem creating X509 Aux certificate: problem parsing cert: Duplicate extensions not allowed (OpenSSL::SSL::SSLError)
    Excon::Errors::SocketError: problem creating X509 Aux certificate: problem parsing cert: Duplicate extensions not allowed (OpenSSL::SSL::SSLError)
    from org/jruby/ext/openssl/ `setup'
    from org/jruby/ext/openssl/ `initialize'
    from /Users/mike/.rvm/gems/jruby-1.7.4/gems/excon-0.25.3/lib/excon/ssl_socket.rb:64:in `initialize'
    from /Users/mike/.rvm/gems/jruby-1.7.4/gems/excon-0.25.3/lib/excon/connection.rb:361:in `socket'
    from /Users/mike/.rvm/gems/jruby-1.7.4/gems/excon-0.25.3/lib/excon/connection.rb:105:in `request_call'
    from /Users/mike/.rvm/gems/jruby-1.7.4/gems/excon-0.25.3/lib/excon/middlewares/mock.rb:42:in `request_call'

  5. Hi,
    I already have Ruby on rails app with me.Now I wanna integrate this with JRuby in order to get asynchronous feature.How do I proceed.
    Any help would be greatly appreciated,thank you very much.

  6. Thank you for sharing, really useful.

  7. I've had a problem with database creation (according to the errors in tomcat log file):

    Infos: ActiveRecord::JDBCError: [SQLITE_ERROR] SQL error or missing database (no such table: posts): SELECT "posts".* FROM "posts"

    I checker the webapp folder (webapps/blog/WEB-INF/db) in Tomcat home directory, - there is a production.sqlite3 file. How to tell Tomcat to use it ? One more point, it would be better to put that file in another place (in case of sqlite2 DB use), - if not it will be removed after teh next deploy you'll do. Regards.

    1. This comment has been removed by the author.

  8. Stupid, I forgot to run the migrations in production mode. There are two problems for the moment when deploying locally in Tomcat with warbler: compiled assets are not found (see more about that at and ` zip file is empty` error whe starting Tomcat. Event after adding zip-zip gem to the Gemfile didn't change that.

  9. Nice blog ,,, This blog help you to find your DLL file is corrupt or missing .please go through this link.
    How To Remove Rundll Error
    Thank you
    Aalia lyon

  10. Ruby On Rails Online Training, ONLINE TRAINING – IT SUPPORT – CORPORATE TRAINING The 21st Century Software Solutions of India offers one of the Largest conglomerations of Software Training, IT Support, Corporate Training institute in India - +919000444287 - +917386622889 - Visakhapatnam,Hyderabad Ruby On Rails Online Training, Ruby On Rails Training, Ruby On Rails, Ruby On Rails Online Training| Ruby On Rails Training| Ruby On Rails| "Courses at 21st Century Software Solutions
    Talend Online Training -Hyperion Online Training - IBM Unica Online Training - Siteminder Online Training - SharePoint Online Training - Informatica Online Training - SalesForce Online Training - Many more… | Call Us +917386622889 - +919000444287 -

  11. Thanks for this - really helped me out on a Windows installation I don't typically work with!

  12. Another solution for
    OpenSSL::Cipher::CipherError: Illegal key size is to add the following lines in your boot.rb file:

    security_class = java.lang.Class.for_name('javax.crypto.JceSecurity')
    restricted_field = security_class.get_declared_field('isRestricted')
    restricted_field.accessible = true
    restricted_field.set nil, false

  13. Thanks Joe for sharing such a nice information with us. Cryptex technologies is one of the well-known Ruby on Rails development companies in India. If you have any queries feel free to email at:

  14. This listing is certainly very beneficial.This is the right weblog. it's far very interesting weblog Ever. Thanks for giving one of these brilliant article... for another information please check the site

  15. Nice blog..! I really loved reading through this article. Thanks for sharing such an amazing post with us and keep blogging...Well written article Thank You for Sharing with Us pmp training institute in chennai | pmp training class in chennai | pmp training near me | pmp training courses online | pmp training fee