JRuby applications in glassfish – Databases

As I promised earlier, I will now write how I added database support to a JRuby application running under glassfish v2.
The first step you’ll have to do is installing another plugin. The plugin is called “ActiveRecord-JDBC”. You can add this plugin to your rails project by adding “http://jruby-extras.rubyforge.org/svn/trunk/rails-integration/plugins/” to your plugin repositories. If you’re using gem for plugin management, just execute “gem install activerecord-jdbc”.

The second step you’ll have to do is including the Java libraries in your environment. Just edit configure/environment.rb and add “require ‘jdbc_adapter’” to it.

You’re almost done. The last step (and the important one) is to add the new database connectivity to your databases.yml. There you’ll have to edit the “production” section although  you’re developing. Add the following to your configuration:

     production:
      host: localhost
      adapter: jdbc
      driver: com.mysql.jdbc.Driver
      url: jdbc:mysql://localhost/<yourapp>_development
      username: ...
      password: ...

Just recreate your war file and put it in your autodeploy folder. Your JRuby application should now be able to access the MySQL Database.