Skip to content

Instantly share code, notes, and snippets.

@woodie
Created January 16, 2010 17:38
Show Gist options
  • Save woodie/278913 to your computer and use it in GitHub Desktop.
Save woodie/278913 to your computer and use it in GitHub Desktop.
Gem Bundle, then make a gems.jar

Gems with Java extensions on App Engine

While creating the gems.jar, we simply divert any jar files directly to WEB-INF/lib

=> Packaging gems
Installing fast_xs.jar
Installing hpricot_scan.jar

As long as we don’t have name collisions, the extension jar files work from WEB-INF/lib

. 9262117 ... appengine-api-1.0-sdk-1.3.0.jar
.  583552 ... appengine-api-labs-1.3.0.jar
. 8986963 ... appengine-jruby-0.0.7.pre.jar
.   13465 ... fast_xs.jar
. 5926408 ... gems.jar
.   55431 ... hpricot_scan.jar
.  152043 ... jruby-rack-0.9.6.jar

This required the most recent build of appengine-tools 0.0.8.pre

sudo gem uninstall appengine-tools
sudo gem install appengine-tools --pre
require 'zip/zipfilesystem'
require 'rubygems/command_manager'
require 'appengine-tools/bundler'
module AppEngine
module Admin
TARGET_VERSION = '1.8'
TARGET_ENGINE = 'jruby'
GEM_PLATFORM = Gem::Platform.new("universal-java-#{TARGET_VERSION}")
class GemBundler
# . . .
def gem_bundle(args)
return unless args.include?('--update') || gems_out_of_date
Gem.platforms = [Gem::Platform::RUBY, GEM_PLATFORM]
Gem.configuration = Gem::ConfigFile.new(args.unshift('bundle'))
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : nil
# Override RUBY_ENGINE (we bundle from MRI for JRuby)
Object.const_set('RUBY_ENGINE', TARGET_ENGINE)
puts "=> Bundling gems"
begin
Dir.chdir(@root) do
Gem::CommandManager.instance.run(Gem.configuration.args)
end
rescue Gem::SystemExitException => e
exit e.exit_code unless e.exit_code == 0
end
# Restore RUBY_ENGINE (limit the scope of this hack)
Object.const_set('RUBY_ENGINE', ruby_engine) unless ruby_engine.nil?
bundler_dir = "#{app.gems_dir}/bundler_gems"
target_pair = "#{TARGET_ENGINE}/#{TARGET_VERSION}"
gem_patch = "require 'bundler_gems/#{target_pair}/environment'"
File.open("#{bundler_dir}/environment.rb",'w') {|f| f << gem_patch }
FileUtils.rm app.gems_jar, :force => true # blow away the old jar
puts "=> Packaging gems"
gem_files = Dir["#{bundler_dir}/#{target_pair}/dirs/**/**"] +
Dir["#{bundler_dir}/#{target_pair}/gems/**/**"] +
Dir["#{bundler_dir}/#{target_pair}/environment.rb"] +
Dir["#{bundler_dir}/environment.rb"]
Zip::ZipFile.open(app.gems_jar, 'w') do |jar|
gem_files.reject {|f| f == app.gems_jar}.each do |file|
if file[-4..-1].eql? '.jar'
puts "Installing #{File.basename(file)}"
FileUtils.cp file, app.webinf_lib
else
jar.add(file.sub("#{app.gems_dir}/",''), file)
end
end
end
end
# . . .
end
end
end
# Critical default settings:
disable_system_gems
disable_rubygems
bundle_path '.gems/bundler_gems'
# List gems to bundle here:
gem 'rails_dm_datastore'
gem 'rails', "2.3.5"
gem 'i18n'
gem 'tzinfo'
gem 'builder'
gem 'hpricot', '0.8.2'
gem 'mechanize', '0.8.5'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment