Last updated January 18, 2011 06:16, by qmxme
DO NOT EDIT - MOVED TO HERE => <a href="http://wiki.jruby.org/JRubyOnRailsOnBEAWeblogic">JRubyOnRailsOnBEAWeblogic</a>
[[Home|» JRuby Project Wiki Home Page]] [[JRubyOnRails#War_File_Deployment|» JRuby on Rails: War File Deployment]]
<h1> JRuby on Rails on Oracle WebLogic</h1>
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 [http://www.oracle.com/appserver/appserver_family.html Oracle WebLogic], such as version 11g.''
<br/><br/>
__TOC__
== Prerequisites ==
* [http://dist.codehaus.org/jruby/1.1.1/ JRuby 1.1.1]
* [http://java.sun.com/javase/downloads/index_jdk5.jsp Java JDK 5]
* [http://e-docs.bea.com/platform/suppconfigs/configs100/100_over/overview.html Oracle WebLogic 10]
* [http://dev.mysql.com/downloads/mysql/5.0.html MySQL Database v 5]
* <a href="{{project warbler page home}}">Warbler</a>
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 ==
# Download and install [http://java.sun.com/javase/downloads/index_jdk5.jsp JDK 5] and [http://dist.codehaus.org/jruby/1.1.1/ JRuby 1.1.1], and make sure you set <tt>JAVA_HOME/bin</tt> and <tt>JRUBY_HOME/bin</tt> in your PATH environment variable.
# Install Rails 2.0:<br/><tt> jruby -S gem install rails</tt>
# Install the activerecord-jdbcmysql-adapter gem:<br/><tt> jruby -S gem install activerecord-jdbcmysql-adapter</tt>
# Install the JRuby Open SSL gem:<br/><tt> jruby -S gem install jruby-openssl</tt>
== Creating and Running a Rails 2.0 Application ==
# Create a Rails application:<br/><tt> jruby -S rails books --database=mysql</tt><br/>This will generate the skeleton of a Rails application.
# Navigate to the <tt>books/</tt> directory and scaffold a book controller and model:<br/><tt> jruby script/generate scaffold book title:string author:string isbn:string desription:text</tt>
# Start the MySQL database server.
# Set the username and password for your database server in <tt>config/database.yml</tt>. The default for MySQL is <tt>username: root</tt> and a blank password.
# Change the adapter from <tt>mysql</tt> to <tt>jdbcmysql</tt> in <tt>config/database.yml</tt>.
# Create the required databases:<br/><tt> jruby -S rake db:create:all</tt><br/>This creates the three databases in <tt>database.yml</tt>, namely:
#* books_development
#* books_test
#* books_production
# Create required tables by running your migrations in all environments:<br/><tt> jruby -S rake db:migrate</tt><br/><tt> jruby -S rake db:migrate RAILS_ENV=test</tt><br/><tt> jruby -S rake db:migrate RAILS_ENV=production</tt>
# Start your application by using WEBrick:<br/><tt> jruby script\server</tt>
# Point your browser at:<br/><tt> <nowiki>http://localhost:3000/books</nowiki></tt>
Your Rails application is now running on Java with the Ruby MySQL adapter.
== Packaging a Rails Application Into a WAR ==
# Install the warbler gem:<br/><tt> jruby -S gem install warbler</tt>
# Generate the warbler configuration file:<br/><tt> jruby -S warble config</tt>
# Modify <tt>books/config/warble.rb</tt> to include additional gems:<br/><tt> config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]</tt><br/> 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 <tt>books.war</tt>:<br/><tt> warble war</tt>
# If for some reason the Rails gem was not included, try freezing Rails:<br/><tt> jruby -S rake rails:freeze:gems</tt>
== Deploying to Oracle WebLogic ==
# Create a new WebLogic domain.
# Start the admin server.
# Point your browser at:<br/><tt> <nowiki>http://localhost:7001/console</nowiki></tt>
# 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:<br/><tt> <nowiki>http://localhost:7001/books/books</nowiki></tt>
# 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.
== Using a JDBC Datasource in WebLogic==
===Configuring WebLogic ===
Create a new datasource in the WebLogic console.
# JDBC datasoure properties:<br/><tt> Name: books_production_ds<br/> JNDI name: jdbc/books_production_ds <br/> Databse type: MySQL <br/> Database driver: com.mysql.jdbc.Driver</tt>
# Transaction options: Keep default transaction options.
# Connection properties:<br/><tt> Database_name: books_production<br/> Host name: localhost<br/> Port: 3306<br/> Database user name: root <br/> Password: <leave blank></tt>
# Test configuration: Connection test should succeed.
# Targets
## Select AdminServer.
## Finish and activate changes.
=== Configuring the Rails Application ===
# Edit <tt>books/config/database.yml</tt>.
# Replace the <tt>production</tt> block with:<br/><tt> production:<br/> adapter: jdbc<br/> jndi: jdbc/books_production_ds</tt>
# Package your application using warble:<br/><tt> jruby -S warble</tt>
=== Updating the Application in WebLogic ===
# Update the WAR application in the WebLogic console
# Point your browser at:<br/><tt> <nowiki>http://localhost:7001/books/books</nowiki></tt>
That's it!
== Known Issues ==
If you get this [http://www.ruby-forum.com/topic/155930 error], you need to update JRuby-Rack (currently version 0.9.4) to handle WebLogic returning null from the call to <tt>ServletContext.getRealPath(String)</tt>.
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 [http://jira.codehaus.org/browse/JRUBY-1401 this patch] to JRuby, and include your patched <tt>jruby-complete.jar</tt> in your rails app's <tt>lib</tt> directory. Add the following line to your <tt>config/warble.rb</tt> file to prevent Warbler from overwriting your patched jar:
config.java_libs.reject! { |lib| lib =~ /jruby-complete/ }
If you get an '<tt>Unknown database</tt>' error when you <tt>db:migrate</tt>, run
jruby script/generate jdbc
Then proceed to create the required databases (<tt>jruby -S rake db:create:all</tt>) and continue the above steps from there. Do not change the adapter name in <tt>config/database.yml</tt>. The adapter name should remain <tt>mysql</tt> (not <tt>jdbcmysql</tt>).
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]





