-
Notifications
You must be signed in to change notification settings - Fork 0
JRubyOnRailsOnBEAWeblogic
» JRuby Project Wiki Home Page » JRuby on Rails: War File Deployment
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.
- 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.
- Install Rails 2.0:
jruby -S gem install rails - Install the activerecord-jdbcmysql-adapter gem:
jruby -S gem install activerecord-jdbcmysql-adapter - Install the JRuby Open SSL gem:
jruby -S gem install jruby-openssl
- Create a 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 the MySQL database server.
- Set the username and password for your database server in config/database.yml. The default for MySQL is username: root and a blank password.
- Change the adapter from mysql to jdbcmysql in config/database.yml.
- 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
- 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 - Start your application by using WEBrick:
jruby script\server - Point your browser at:
http://localhost:3000/books
- Install the 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-jdbcmysql-adapter", "jruby-openssl"]
These gems will be included in the generated war file. The Rails gem will be included by default. - Use warbler to package the rails app into a war and create books.war:
warble war - If for some reason the Rails gem was not included, try freezing Rails:
jruby -S rake rails:freeze:gems
- Create a new WebLogic domain.
- Start the admin server.
- Point your browser at:
http://localhost:7001/console - Install the WAR application you 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.
Create a new datasource in the WebLogic console.
- JDBC datasoure properties:
Name: books_production_ds<br/> JNDI name: jdbc/books_production_ds <br/> Databse type: MySQL <br/> Database driver: com.mysql.jdbc.Driver - Transaction options: Keep default transaction options.
- Connection properties:
Database_name: books_production<br/> Host name: localhost<br/> Port: 3306<br/> Database user name: root <br/> Password: <leave blank> - Test configuration: Connection test should succeed.
- Targets
- Select AdminServer.
- Finish and activate changes.
- Edit books/config/database.yml.
- Replace the production block with:
production:<br/> adapter: jdbc<br/> jndi: jdbc/books_production_ds - Package your application using warble:
jruby -S warble
- Update the WAR application in the WebLogic console
- Point your browser at:
http://localhost:7001/books/books
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