Running Padrino on JRuby

You can run Padrino (0.9.29 ... 0.17.0 is tested) on JRuby


Install on JRuby

You can easily install Padrino on jruby when you use RVM:

$ rvm install jruby-latest
$ rvm use --create jruby-latest@padrino
$ gem install bundler
$ gem install padrino -v=0.17.0

Create Padrino project just as you do when using MRI or REE:

$ padrino g project jrack-test -e erb

cd ./jrack-test and you should edit Gemfile:

# JRuby deployment requirements
# please add these lines...
gem 'jruby-openssl'
gem 'jruby-rack'
gem 'warbler'

Now you can go:

$ bundle install && bundle binstubs --all

Then, create the test controller:

$ padrino gen controller index get:index get:hello get:show_path

A controller sample is here:

# app/controllers/index.rb

JrackTest::App.controllers :index do
  get :index do
    "Hello, JPadrino!"
  end

  get :hello, map: '/:id' do
    "Hello, #{params[:id]}!"
  end

  get :show_path, map: '/show-path/*urls' do
    "You accessed: #{params[:urls].inspect}"
  end
end

Then run:

$ padrino s

To run JRuby on 1.9 compat mode:

Note: Modern JRuby (9.x+) defaults to Ruby 2.6+ compatibility and no longer requires the --1.9 flag. The example below applies only to legacy JRuby 1.7.x.

alias padrino='jruby --1.9 -S padrino'
padrino start

You can access http://localhost:3000 as you run padrino on MRI...


How to create WAR

Now you should install the warbler gem with $ gem install warbler, so you can:

$ warble config

Edit config/warble.rb if you want to apply some customizations. You can access JRuby-Rack official README and Warbler rdoc.

For example, if you want to deploy the app to server root directory, just add to config/warble.rb:

config.jar_name = "jrack-test"

Deploying with JRuby on 1.9 compat mode (obsolete for modern JRuby 9.x+, which defaults to Ruby 2.6+ compatibility):

config.webxml.jruby.compat.version = "1.9"

If you are ready, run:

$ warble war

You would get jrack-test.war (the same name as your project directory name), and you can deploy this war file to tomcat! I tested on tomcat 6.0.20, and it works well with quick response.

Type to search the guides.