-
Notifications
You must be signed in to change notification settings - Fork 0
JrubyOnRailsOnTomcat
- Ruby on Rails 1.1
- Java 5
- Subversion
- Tomcat 5.5
- JRuby 1.0.2
- Create a rails app the normal way
rails my-project cd my-project
- Install ActiveRecord-JDBC
$JRUBY_HOME/bin/gem install activerecord-jdbc-adapter -y
- Install Goldspike
jruby script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike
- modify
database.yml
development: adapter: jdbc driver: com.mysql.jdbc.Driver url: jdbc:mysql://localhost/blabla_development username: root password: root
- Modify
environment.rb
require File.join(File.dirname(__FILE__), 'boot') if RUBY_PLATFORM =~ /java/ require 'rubygems' RAILS_CONNECTION_ADAPTERS = %w(jdbc) end Rails::Initializer.run do |config|
- Run generator
jruby script/generate goldspike
this will set up the WEB-INF
dir and generate a web.xml
- Copy jars to
WEB-INF/lib
in rails project dir
- Build an app
- Run migrations like this
jruby -S rake db:migrate jruby -S rake db:migrate RAILS_ENV=production
- Run a testing server like this
jruby -S rake war:standalone:run
This command will build a war file you can deploy in Tomcat:
jruby -S rake war:standalone:create
http://blog.nicksieger.com/articles/2007/10/25/jruby-on-rails-fast-enough
- Ruby on Rails 2.0.2
- Warbler (minimal, flexible, ruby-like way to create .war file)
- Java 6
- Tomcat 6
- JRuby 1.0.3
Note Other versions of Java, Rails 2.x, and Tomcat may work
jruby -S gem install -y rails warbler
Create .war
$RAILS_APP_ROOT/jruby -S warble war
Create config/warble.rb
$RAILS_APP_ROOT/jruby -S warble config
Clean .war
$RAILS_APP_ROOT/jruby -S warble war:clean
Note: C Ruby works fine as well
Copy the generated file $YOUR_APP_NAME.war to $TOMCAT_HOME/webapps and it should auto deploy
Go to http://localhost:8080/$YOUR_APP_NAME to verify that the app is running; check $TOMCAT_HOME/logs/catalina.out in case of problems.
An easy way to see log information from Ruby is to add the following to environment.rb:
config.logger = Logger.new(STDOUT)
Open JIRA Issues matching "Rails 2.0" Goldspike Servlet JIRA Issues
Rails Error: No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store)
Goldspike hasn't been updated to handle Rails 2.0 gracefully, so you need to let Rails take care of session storage. You do that by editing your web.xml and adding this value:
<pre> <context-param> <param-name>jruby.session_store</param-name> <param-value>db</param-value> </context-param>
See Warbler Web.xml section for options on how to do this. A sample of how the web.xml.erb should look like after making this change is here.
Random Empty Response with Rails 2.0 (Resolved in 1.1)
Truncated HTTP POSTs in >= 1.1RC2
These are the only .jar files that are required.
File locations: http://repository.codehaus.org/org/jruby/jruby-complete/1.1RC3 http://repository.codehaus.org/org/jruby/extras/goldspike/1.6/goldspike-1.6.jar
If you want to build JRuby & Goldspike from trunk & use Warbler, you currently have to jump through some hoops. The basic shell script below is one way to do it that works. It is meant as documentation rather than a $$ solution.
Note, the Goldspike that comes with Warbler should not be used with 1.0.3 & will not work with trunk. You also need to download backport-util-concurrent to $BACKPORT_UTIL_CONCURRENT_LOCATION & it must be included in your .war. (moved into the warbler gem lib prior to running jruby -S warble war).
See Warbler for an alternate approach to substituting jars that is simpler than changing the Warbler gem libs.
#!/bin/bash # JRuby Env export JRUBY_HOME=`pwd`/jruby export PATH=$PATH:$JRUBY_HOME/bin echo "#### Checking out####" svn co http://svn.codehaus.org/jruby/trunk/jruby jruby echo "#### Building ####" cd jruby ant jar-complete echo "#### Installing required gems - Add whatever else you need ####" jruby -S gem install -y --no-ri --no-rdoc rails jruby-openssl rest-open-uri activerecord-jdbc-adapter warbler echo "### Replacing Goldspike Version with Latest (Assuming you built that already)" cp $RAILS_INTEGRATION_HOME/target/goldspike-1.4-SNAPSHOT.jar lib/ruby/gems/1.8/gems/warbler-0.9.1/lib echo "### Adding required backport-util-concurrent jar" # Not needed after 1.1RC1 cp $BACKPORT_UTIL_CONCURRENT_LOCATION/backport-util-concurrent-Java60-3.1/backport-util-concurrent.jar lib/ruby/gems/1.8/gems/warbler-0.9.1/lib echo "#### Replacing JRuby version in warbler gem with one just built (trunk)" cp lib/jruby-complete.jar lib/ruby/gems/1.8/gems/warbler-0.9.1/lib if [ -f lib/ruby/gems/1.8/gems/warbler-0.9.1/lib/jruby-complete-1.0.1.jar ]; then echo "Removing 1.0.1 Jruby" rm lib/ruby/gems/1.8/gems/warbler-0.9.1/lib/jruby-complete-1.0.1.jar fi echo "#### Creating .war ####" cd $RAILS_APP_ROOT jruby -S warble war