Skip to content

Instantly share code, notes, and snippets.

Created Sep 29, 2010
What would you like to do?
- Install Bundler
> jruby -S gem install bundle --no-ri --no-rdoc
- Create and Edit Gemfile
> cd [some directory to install gems]
> jruby -S bundle init
> vim Gemfile
# A sample Gemfile
source ""
# gem "rails"
gem "dm-core"
gem "dm-timestamps"
gem "dm-sqlite-adapter"
- Install gems to vendor directory
> jruby -S bundle install --path=vendor
- Write Java code with JRuby embed
String basepath = System.getProperty("user.dir");
ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
container.setHomeDirectory("/Users/yoko/Tools/jruby-1.5.3"); // needs for "require 'rubygems'"
System.out.println("jrubyhome: " + container.getHomeDirectory());
// tell jruby where the Gemfile is located.
container.runScriptlet("ENV['BUNDLE_GEMFILE'] = \"" + basepath + "/build/ruby/Gemfile\"");
container.runScriptlet("require 'rubygems'");
container.runScriptlet("require 'bundler/setup'");
container.runScriptlet("require 'dm-core'");
container.runScriptlet("require 'dm-timestamps'");
container.runScriptlet("DataMapper.setup(:default, 'sqlite::memory:')");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment