Run Rails app on Tomcat Successfully

阅读更多

Package up Rails app as WAR file & Run it on Tomcat Successfully

            
             (please excuse me for writing in English, for there's no input method installed on client's machine)
  • This short HOW-TO includes 9 steps. Basically, you need to install two adapters in your Rails application to support WAR package.

1. Get your Rails application running in production mode.

  • This is because the plugin that will be used to generate the war file only works in production mode.

2. Install plugin GoldSpike by executing

  • $ script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike

  • NOTE: This is the adapter for input of your Rails application.

3. Install gem package activerecord-jdbc by executing

  • $ gem install activerecord-jdbc --no-rdoc --no-ri

  • NOTE: This is the adapter for output of your Rails application.

4. Modify config/database.yml file by using jdbc as the database adapter. E.g.

  • production:
      adapter: jdbc

      driver: com.mysql.jdbc.Driver
      url: jdbc:mysql://localhost/
      username: 
      password: 
      host: 

5. Modify config/environment.rb by adding

  • require 'jdbc_adapter' (NOT require 'active_record/connection_adapters/jdbc_adapter' as Rails-Integration's Wiki said!)

    • just blow line

    require File.join(File.dirname(__FILE__), 'boot')

6. Set and export $JRUBY_HOME, this will be used by GoldSpike plugin when generating WAR file.
    Actuall, you  can put all jar files used by GoldSpike under $JRUBY_HOME/lib to avoid downloading them when you generating the war file with rake, it's really annoying when you have to wait for the download complete.These jar files are (the version I use):

- activation-x.x.jar (1.1)
- bcprov-jdk14-xxx.jar (124)
- commons-pool-x.x.x.jar (1.3)
- jruby-complete-x.x.x.jar (0.9.9)
- rail-integration-x.x.x.jar (1.1.1)
- jetty-x.x.x.jar (6.1.1)

7. Put .jar (e.g., mysql-connector-java-5.0.5-bin.jar for MySQL) under $JRUBY_HOME/lib.

8. Generate standalone war file by executing

  • rake war:standalone:create

9. Test the war file by executing

  • rake war:standalone:run

    This use jetty. Of coure, you can deploy it to your Tomcat.

KNOWN ISSUES

  • On Tomcat, when we tried to start up the second Rails application, we got OutOfMemoryException, and we don't know whether this has something to do with the way we connect to the database.

你可能感兴趣的:(Rails,Tomcat,jruby,JDBC,MySQL)