Last updated January 18, 2011 06:16, by qmxme
DO NOT EDIT - MOVED TO HERE => <a href="http://wiki.jruby.org/JrubyOnRailsOnTomcat">JrubyOnRailsOnTomcat</a>
__TOC__
== Rails 1.1 ==
=== Prerequisites ===
* Ruby on Rails 1.1
* Java 5
* Subversion
* Tomcat 5.5
* JRuby 1.0.2
=== Environment setup ===
* Create a rails app the normal way
<pre>
rails my-project
cd my-project
</pre>
* 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 <code>database.yml</code>
<pre>
development:
adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/blabla_development
username: root
password: root
</pre>
* Modify <code>environment.rb</code>
<pre>
require File.join(File.dirname(__FILE__), 'boot')
if RUBY_PLATFORM =~ /java/
require 'rubygems'
RAILS_CONNECTION_ADAPTERS = %w(jdbc)
end
Rails::Initializer.run do |config|
</pre>
=== Developing ===
* Run generator
jruby script/generate goldspike
this will set up the <code>WEB-INF</code> dir and generate a web.xml
* Copy jars to <code>WEB-INF/lib</code> in rails project dir
* Build an app
* Run migrations like this
<pre>
jruby -S rake db:migrate
jruby -S rake db:migrate RAILS_ENV=production
</pre>
* Run a testing server like this
jruby -S rake war:standalone:run
=== Deployment ===
This command will build a war file you can deploy in Tomcat:
jruby -S rake war:standalone:create
=== Benchmark ===
http://blog.nicksieger.com/articles/2007/10/25/jruby-on-rails-fast-enough
== Rails 2.0 ==
=== Prerequisites ===
* Ruby on Rails 2.0.2
* [[Warbler | 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''
=== Environment setup ===
<pre>
jruby -S gem install -y rails warbler
</pre>
=== Development ===
Create .war
<pre>
$RAILS_APP_ROOT/jruby -S warble war
</pre>
Create config/warble.rb
<pre>
$RAILS_APP_ROOT/jruby -S warble config
</pre>
Clean .war
<pre>
$RAILS_APP_ROOT/jruby -S warble war:clean
</pre>
''Note: C Ruby works fine as well''
=== Deployment ===
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.
=== Logging ===
An easy way to see log information from Ruby is to add the following to environment.rb:
<pre>
config.logger = Logger.new(STDOUT)
</pre>
=== Known Issues ===
[http://jira.codehaus.org/secure/IssueNavigator.jspa?reset=true&&query=rails+2.0&summary=true&description=true&body=true&pid=11295&status=1&status=3 Open JIRA Issues matching "Rails 2.0"]
[http://jira.codehaus.org/secure/IssueNavigator.jspa?reset=true&&pid=11295&component=12785&sorter/field=priority&sorter/order=DESC 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> <!-- This value really means let Rails take care of session store -->
</context-param>
</pre>
See [http://caldersphere.rubyforge.org/warbler/ 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 [http://pastie.caboo.se/134120 here].
'''[http://jira.codehaus.org/browse/JRUBY-1879 Random Empty Response with Rails 2.0]''' (Resolved in 1.1)
'''[http://jira.codehaus.org/browse/JRUBY-2314 Truncated HTTP POSTs in >= 1.1RC2 ]
=== JRuby 1.1RC3 and Goldspike 1.6 ===
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
=== Building JRuby & Goldspike from trunk ===
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 [http://backport-jsr166.sourceforge.net/index.php 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.
<pre>
#!/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
</pre>





