Skip to content

Instantly share code, notes, and snippets.

@JackDanger
Created June 4, 2009 02:20
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 JackDanger/123391 to your computer and use it in GitHub Desktop.
Save JackDanger/123391 to your computer and use it in GitHub Desktop.
# App Engine Rack
#
# Unified Script to build an JRuby App Engine
# app from scratch. Example app is Sinatra
# but any rack-enabled framework will work
# (e.g. Rails, Ramaze, your own custom app)
#
# Uncomment the lines near the bottom for installing
# the App Engine Java SDK if you don't have it
# already (but be warned: it's a 20MB+ download).
# If you already have the SDK somewhere on your computer
# then run this file like so:
#
# APPENGINE_JAVA_SDK_INSTALL="/path/to/appengine-java-sdk-1.2.1/" app_engine_rack.sh
#
# This script is a combination of work by Ola Bini
# (http://olabini.com/blog/2009/04/jruby-on-rails-on-google-app-engine/)
# and Samuel Goebert
# (http://blog.bigcurl.de/2009/04/running-sinatra-apps-on-google.html).
# Assembled by Jack Danger Canty
#
mkdir appengine_app
cd appengine_app
# make the basic file structure
mkdir config
mkdir views
mkdir lib
mkdir public
mkdir vendor
# grab jruby
cd vendor
git clone git://github.com/jruby/jruby.git
cd jruby
rake build
./bin/jruby -S gem install rake warbler sinatra
./bin/jruby -S gem install JackDanger-wave --source http://gems.github.com
cd ../..
# install jruby-rack.jar to ./lib
curl http://kenai.com/downloads/jruby-rack/jruby-rack-0.9.4.jar -O
mv jruby-rack*.jar ./lib/
# install jruby-complete.jar to ./lib
curl http://dist.codehaus.org/jruby/current/jruby-complete-1.3.0.jar -o lib/jruby-complete.jar
# split up the jruby-complete.jar:
# (borrowed from Ola Bini)
cd lib
rm -rf jruby-core.jar
rm -rf ruby-stdlib.jar
rm -rf tmp_unpack
mkdir tmp_unpack
cd tmp_unpack
jar xf ../jruby-complete.jar
cd ..
mkdir jruby-core
mv tmp_unpack/org jruby-core/
mv tmp_unpack/com jruby-core/
mv tmp_unpack/jline jruby-core/
mv tmp_unpack/jay jruby-core/
mv tmp_unpack/jruby jruby-core/
cd jruby-core
jar cf ../jruby-core.jar .
cd ../tmp_unpack
jar cf ../ruby-stdlib.jar .
cd ..
rm -rf jruby-core
rm -rf tmp_unpack
rm -rf jruby-complete.jar
cd ..
# NOTE: we're going to create a Sinatra app to start
# but you can run any rack app you want.
# From here on your application is your own - edit
# config.ru to run any rack app you like and update
# config/warble.rb to make sure all the right dependencies
# are included. Google "config.ru" for ideas.
# create config.ru
curl http://gist.github.com/raw/91801/394280200b2ea1fb52c12dd89a9dfb613d16fd88/config.ru > config.ru
# add warble.rb to config/
curl http://gist.github.com/raw/91801/2f645511eaaa8945aa52902d41fba152b9397e33/warble.rb > config/warble.rb
# create an appengine-web.xml file
curl http://gist.github.com/raw/91801/4d174ec2c681ab64418afb464dfb9c1cd9a9599c/appengine-web.xml > appengine-web.xml
# add a basic Sinatra app to app.rb
cat > app.rb <<EOM
require 'rubygems'
require 'sinatra'
get '/' do
"Hello from Sinatra running on Java!"
end
EOM
# INSTALL App Engine Java SDK
# uncomment if you want this automated and
# don't mind the 20MB download.
curl -O http://googleappengine.googlecode.com/files/appengine-java-sdk-1.2.1.zip
unzip appengine-java-sdk-1.2.1.zip
# set the APPENGINE_JAVA_SDK_INSTALL env var
# to wherever you installed the SDK. Default
# assumes you uncommented the above download lines.
# If you already have the SDK installed then run
# this file like so:
#
# APPENGINE_JAVA_SDK_INSTALL="/path/to/appengine-java-sdk-1.2.1/" app_engine_rack.sh
#
if [ 'x' == "x$APPENGINE_JAVA_SDK_INSTALL" ]; then
APPENGINE_JAVA_SDK_INSTALL=appengine-java-sdk-1.2.1
fi
# copy the appengine SDK .jar from the SDK files (wherever you have them)
cp $APPENGINE_JAVA_SDK_INSTALL/lib/user/appengine-api-1.0-sdk-1.2.1.jar ./lib/
# prepare a warfile
./vendor/jruby/bin/jruby -S warble
# start the server
$APPENGINE_JAVA_SDK_INSTALL/bin/dev_appserver.sh tmp/war/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment