JRuby on Rails on BEA Weblogic
From JRubyWiki
Contents |
[edit]
JRuby on Rails on BEA Weblogic
[edit]
Prerequisites
- JRuby 1.1.1
- Java 5
- BEA Weblogic 10
- MySQL database v 5
- Warbler
The JRuby 1.1 series requires Java 5 which started getting supported by BEA Weblogic version 9.2. In this example we're using BEA Weblogic 10
[edit]
Installation
- Download and install JDK 5, JRuby 1.1.1 and make sure you set $JAVA_HOME/bin and $JRUBY_HOME/bin in your $PATH variable.
- Install Rails 2.0:
jruby -S gem install rails
- Install activerecord-jdbc-adapter gem:
jruby -S gem install activerecord-jdbc-adapter
- Install jruby open ssl gem:
jruby -S gem install jruby-openssl
[edit]
Create a Rails 2.0 Application
- Create Rails application:
jruby -S rails books --database=mysql
This will generate the skeleton of a Rails application.
- 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
- Start MySQL database server
- Set username and password for your database server in config/database.yml. Default for MySQL is username: root and a blank password
- Create required databases:
jruby -S rake db:create:all
This creates the 3 databases in database.yml, namely:
books_development books_test books_production
- 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
- Edit books/app/controllers/application.rb, and remove the # in front of :secret:
protect_from_forgery :secret => '17cb6f2535d9d55c77a2f1e66e2fb7d9'
- Start your application using WEBrick:
jruby -S jruby script\server
- Point your browser at:
http://localhost:3000/books
Your Rails application is now running on Java, with Ruby MySQL adapter.
[edit]
Packaging Rails application into WAR
- Install warbler gem:
jruby -S gem install warbler
- Generate the warbler configuration file
jruby -S warble config
- Modify books/config/warble.rb to include additional gems:
config.gems = ["activerecord-jdbc-adapter", "jruby-openssl"]
These gems will be included in the generated war file. The Rails gem will be included by default.
[edit]
Deploying to BEA Weblogic
- Create a new Weblogic domain
- Start the admin server
- Point your browser at:
http://localhost:7001/console
- Install WAR application previously packaged and start it (For this example it can be installed on the Admin server)
- Point your browser at
http://localhost:7001/books/books
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 like "the server is currently overloaded", you should try to reload it.
[edit]
Using JDBC datasource in Weblogic
[edit]
Weblogic configuration
- Create a new datasource in the Weblogic console
- JDBC datasoure properties
Name: books_production_ds JNDI name: jdbc/books_production_ds Databse type: MySQL Database driver: com.mysql.jdbc.Driver
- Transaction options
- Keep default transaction options
- Connection properties
- Transaction options
Database_name: books_production Host name: localhost Port: 3306 Database user name: root Password: <leave blank>
- Test configuration
- Connection test should succeed
- Targets
- Select AdminServer
- Finish and activate changes
- Test configuration
[edit]
Rails application configuration
- Edit books/config/database.yml
- Replace the production block with:
production:
adapter: jdbc
jndi: jdbc/books_production_ds
- Package you application using warble:
jruby -S warble
[edit]
Updating application in Weblogic
- Update the WAR application in the Weblogic console
- Point your browser at:
http://localhost:7001/books/books
That's it!

