Skip to content

Instantly share code, notes, and snippets.

@yokolet
Created September 29, 2010 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokolet/603328 to your computer and use it in GitHub Desktop.
Save yokolet/603328 to your computer and use it in GitHub Desktop.
- 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 "http://rubygems.org"
# 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("Bundler.require");
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