Skip to content
Olle Jonsson edited this page Nov 15, 2017 · 16 revisions

JRuby's standard launcher honors the JAVACMD environment variable to locate the main Java command. When we set this environment variable to drip JRuby will automatically use drip (instead of the standard java command).

Just set the JAVACMD environment variable:

export JAVACMD=$(which drip)

Or provide a path if drip is not on your PATH:

export JAVACMD=~/bin/drip

In JRuby 1.7.1 a custom drip initial class was created org.jruby.main.DripMain. This can be defaulted using the DRIP_INIT_CLASS environment variable.

Set the DRIP_INIT_CLASS environment variable:

export DRIP_INIT_CLASS=org.jruby.main.DripMain
export DRIP_INIT="" # Needs to be non-null for drip to use it at all!

Now you can run code like this:

bin/jruby -e 'puts 9 * 9'

The JRuby initial class also supports loading more of your environment. If the file ./dripmain.rb exists, then that file will be loaded into waiting JVM instance. You could load libraries that you don't expect to change frequently here.

An example of this for a project managed by Bundler might look like

require 'rubygems'
require 'bundler'

# Pick groups as appropriate
Bundler.require(:default, :test, :development)

Using Drip with an RVM-installed JRuby

Setting up RVM to automatically use drip with JRuby is pretty easy. Just create the following after use hook in $rvm_path/hooks/after_use_jruby_drip:

#!/usr/bin/env bash

if [[ "${rvm_ruby_string}" =~ "jruby" ]]
then
  export JAVACMD=`which drip`
  export DRIP_INIT_CLASS=org.jruby.main.DripMain
  export DRIP_INIT="" # Needs to be non-null for drip to use it at all!

  # settings from: https://github.com/jruby/jruby/wiki/Improving-startup-time
  export JRUBY_OPTS="-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify" 
fi

Then make that hook file executable:

chmod +x $rvm_path/hooks/after_use_jruby_drip

Using Drip with Standalone JRuby

JRuby can be used as a standalone jar file (no special installation needed). Just download the latest jar from http://jruby.org/download and then you can run some code like this:

drip -cp jruby.jar org.jruby.main.DripMain -e 'puts 8 * 8'

Performance

# standard jruby-1.7.2 (no drip)
\time -p rake environment > /dev/null
real        12.96
user        27.92
sys          2.00

# jruby-1.7.2 with drip first run (dripmain.rb: "require_relative 'config/application'")
\time -p rake environment > /dev/null                   
real         8.78
user        11.98
sys          1.48
 
# jruby-1.7.2 with drip subsequent runs (dripmain.rb: "require_relative 'config/application'")
\time -p rake environment > /dev/null
real         1.71
user         0.06
sys          0.06

Additional Resources

Guide to using drip with JRuby

Drip Experiments (testing by Charles Nutter)

JRuby Drip Initial Class