JRubyOnRailsOnBEAWeblogic

rickyw edited this page Jan 6, 2011 · 10 revisions

» JRuby Project Wiki Home Page     » JRuby on Rails: War File Deployment

JRuby on Rails on Oracle WebLogic

This page describes how to use Oracle WebLogic 10 with JRuby and Rails.

Note: We could use some help verifying the information on this page with later versions of Oracle WebLogic, such as version 11g.

Table of Contents

Prerequisites

The JRuby 1.1.x series releases require Java 5, which was first supported in BEA WebLogic version 9.2. In this example we're using Oracle WebLogic 10.

Installing Java, JRuby, Rails, and Required Gems

  1. Download and install JDK 5 and JRuby 1.1.1, and make sure you set JAVA_HOME/bin and JRUBY_HOME/bin in your PATH environment variable.
  2. Install Rails 2.0:
      jruby -S gem install rails
  3. Install the activerecord-jdbcmysql-adapter gem:
      jruby -S gem install activerecord-jdbcmysql-adapter
  4. Install the JRuby Open SSL gem:
      jruby -S gem install jruby-openssl

Creating and Running a Rails 2.0 Application

  1. Create a Rails application:
      jruby -S rails books --database=mysql
    This will generate the skeleton of a Rails application.
  2. Navigate to the books/ directory and scaffold a book controller and model:
      jruby script/generate scaffold book title:string author:string isbn:string desription:text
  3. Start the MySQL database server.
  4. Set the username and password for your database server in config/database.yml. The default for MySQL is username: root and a blank password.
  5. Change the adapter from mysql to jdbcmysql in config/database.yml.
  6. Create the required databases:
      jruby -S rake db:create:all
    This creates the three databases in database.yml, namely:
    • books_development
    • books_test
    • books_production
  7. Create required tables by running your migrations in all environments:
      jruby -S rake db:migrate
      jruby -S rake db:migrate RAILS_ENV=test
      jruby -S rake db:migrate RAILS_ENV=production
  8. Start your application by using WEBrick:
      jruby script\server
  9. Point your browser at:
      http://localhost:3000/books
Your Rails application is now running on Java with the Ruby MySQL adapter.

Packaging a Rails Application Into a WAR

  1. Install the warbler gem:
      jruby -S gem install warbler
  2. Generate the warbler configuration file:
      jruby -S warble config
  3. Modify books/config/warble.rb to include additional gems:
      config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]
    These gems will be included in the generated war file. The Rails gem will be included by default.
  4. Use warbler to package the rails app into a war and create books.war:
      warble war
  5. If for some reason the Rails gem was not included, try freezing Rails:
      jruby -S rake rails:freeze:gems

Deploying to Oracle WebLogic

  1. Create a new WebLogic domain.
  2. Start the admin server.
  3. Point your browser at:
      http://localhost:7001/console
  4. Install the WAR application you previously packaged and start it. (For this example it can be installed on the Admin server.)
  5. Point your browser at:
      http://localhost:7001/books/books
  6. Replace the application context (first books) with your context if needed.
The first time you access the application it will take quite a while to load. If you get an error message saying something likethe server is currently overloaded, you should try to reload it.

Using a JDBC Datasource in WebLogic

Configuring WebLogic

Create a new datasource in the WebLogic console.

  1. JDBC datasoure properties:
    &nbsp; Name: books_production_ds<br/> &nbsp; JNDI name: jdbc/books_production_ds <br/> &nbsp; Databse type: MySQL <br/> &nbsp; Database driver: com.mysql.jdbc.Driver
  2. Transaction options: Keep default transaction options.
  3. Connection properties:
    &nbsp; Database_name: books_production<br/> &nbsp; Host name: localhost<br/> &nbsp; Port: 3306<br/> &nbsp; Database user name: root <br/> &nbsp; Password: &lt;leave blank&gt;
  4. Test configuration: Connection test should succeed.
  5. Targets
    1. Select AdminServer.
    2. Finish and activate changes.

Configuring the Rails Application

  1. Edit books/config/database.yml.
  2. Replace the production block with:
    &nbsp; production:<br/> &nbsp; adapter: jdbc<br/> &nbsp; jndi: jdbc/books_production_ds
  3. Package your application using warble:
    &nbsp; jruby -S warble

Updating the Application in WebLogic

  1. Update the WAR application in the WebLogic console
  2. Point your browser at:
    &nbsp; http://localhost:7001/books/books
That's it!

Known Issues

If you get this error, you need to update JRuby-Rack (currently version 0.9.4) to handle WebLogic returning null from the call to ServletContext.getRealPath(String).

If you get this error on windows, (note the extra C: at the end of the path.)

     org.jruby.rack.RackInitializationException: No such file or directory - 
     No such file or directory - 
     C:/bea/10.1/wlserver_10.0/samples/domains/wl_server/servers/examplesServer/tmp/_WL_user/books/2htmyu/war/WEB-INF/C:

you need to apply this patch to JRuby, and include your patched jruby-complete.jar in your rails app's lib directory. Add the following line to your config/warble.rb file to prevent Warbler from overwriting your patched jar:

     config.java_libs.reject! { |lib| lib =~ /jruby-complete/ }

If you get an 'Unknown database' error when you db:migrate, run

 jruby script/generate jdbc

Then proceed to create the required databases (jruby -S rake db:create:all) and continue the above steps from there. Do not change the adapter name in config/database.yml. The adapter name should remain mysql (not jdbcmysql). See http://blog.emptyway.com/2008/04/08/120-seconds-guide-to-jruby-on-rails#comment-38471 or http://blog.nicksieger.com/articles/2009/10/12/fresh-0-9-2-activerecord-jdbc-adapter-release

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.