TOTD # 73: JRuby and GlassFish Integration Test #4: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v2 + Warbler
By arungupta on Mar 10, 2009
TOTD #70, #71, #72 shows the first three integration tests that I typically run to ensure that the latest JRuby and GlassFish versions work nicely with each other. #70 showed how to create a trivial Rails application and run it using GlassFish Gem. #71 showed how the same application can be deployed on GlassFish v3 Prelude. #72 showed how to deploy the same application on GlassFish v3.
The next test in the series is to ensure WAR-based deployment of a Rails application continue to work on GlassFish v2. It also shows that JNDI database connection pooling also work as expected. The latest publicly available build is GlassFish v2.1.
Lets begin integration test #4.
- Install Warbler
~/tools/jruby-1.2.0RC2/samples/rails/runner >../../../bin/jruby -S gem install warbler
JRuby limited openssl loaded. gem install jruby-openssl for full support.
Successfully installed warbler-0.9.12
1 gem installed
Installing ri documentation for warbler-0.9.12...
Installing RDoc documentation for warbler-0.9.12...
- Edit "config/database.yml" and change the production
database adapater from:
The changes are highlighted in bold.
Notice "jndi" key/value pair is specified along with "username" and "password". The JNDI reference is created for the GlassFish domain later. The reference is not resolved when this adapter is used with the JRuby CLI and so it falls back to username/password. However this JNDI reference is correctly resolved during runtime when the application is deployed as a WAR file in GlassFish.
- Create and migrate the
production database as:
~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake db:create RAILS_ENV=production
~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake db:migrate RAILS_ENV=production
== CreateRunners: migrating ==================================================
-> 0 rows
== CreateRunners: migrated (0.1170s) =========================================
Note, how "RAILS_ENV=production" is specified at the command-line to ensure the production environment.
- Copy MySQL Connector/J jar in GLASSFISH_HOME/lib as:
~/tools/glassfish/v2.1/glassfish/ >cp ~/tools/mysql-connector-java-5.1.6/mysql-connector-java-5.1.6-bin.jar ./lib
This is required for connection to the MySQL database.
- Fire up GlassFish v2.1 as:
~/tools/glassfish/v2.1/glassfish/bin >./asadmin start-domain
Starting Domain domain1, please wait.
Default Log location is /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/logs/server.log.
Redirecting output to /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/logs/server.log
Domain domain1 started.
Domain [domain1] is running [Sun GlassFish Enterprise Server v2.1 (9.1.1) (build b60e-fcs)] with its configuration and logs at: [/Users/arungupta/tools/glassfish/v2.1/glassfish/domains].
Admin Console is available at [http://localhost:4848].
Use the same port  for "asadmin" commands.
User web applications are available at these URLs:
[http://localhost:8080 https://localhost:8181 ].
Following web-contexts are available:
[/web1 /__wstx-services runner ].
Standard JMX Clients (like JConsole) can connect to JMXServiceURL:
[service:jmx:rmi:///jndi/rmi://Macintosh-187.local:8686/jmxrmi] for domain management purposes.
Domain listens on at least following ports for connections:
[8080 8181 4848 3700 3820 3920 8686 ].
Domain supports application server clusters and other standalone instances.
The logs are created in "domains/domain1/logs/server.log". Optionally, you can specify "--verbose" on the command-line to dump the log on the console itself.
- Create JDBC connection pool as:
~/tools/glassfish/v2.1/glassfish/bin >./asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype javax.sql.DataSource --property "User=duke:Password=glassfish:URL=jdbc\\:mysql\\://localhost/runner_production" jdbc/runner_pool
Command create-jdbc-connection-pool executed successfully.
- Create JDBC resource as:
~/tools/glassfish/v2.1/glassfish/bin >./asadmin create-jdbc-resource --connectionpoolid jdbc/runner_pool jdbc/runner_production
Command create-jdbc-resource executed successfully.
- Create Warbler config file as:
~/tools/jruby-1.2.0RC2/samples/rails/runner >../../../bin/jruby -S warble config
cp /Users/arungupta/tools/jruby-1.2.0RC2/lib/ruby/gems/1.8/gems/warbler-0.9.12/generators/warble/templates/warble.rb config/warble.rb
- Edit "config/warble.rb" to bundle the required gems by
adding the following fragment:
# Include all gems which are used by the web application
BUILD_GEMS = %w(warbler rake rcov)
for gem in Gem.loaded_specs.values
next if BUILD_GEMS.include?(gem.name)
config.gems[gem.name] = gem.version.version
as specified here. And then explicitly specify the runtime gem dependency by adding the following line:
config.gems += ["activerecord-jdbc-adapter"]
right after the previous code fragment. The "activerecord-jdbc-adapter" dependency needs to be explicitly included because this is required only at the runtime and so not resolved correctly by the previous code fragment.
- And create the WAR file as:
~/tools/jruby-1.2.0RC2/samples/rails/runner >../../../bin/jruby -S warble
mkdir -p tmp/war/WEB-INF/gems/specifications
cp /Users/arungupta/tools/jruby-1.2.0RC2/lib/ruby/gems/1.8/specifications/rails-2.2.2.gemspec tmp/war/WEB-INF/gems/specifications/rails-2.2.2.gemspec
mkdir -p tmp/war/WEB-INF/gems/gems
. . .
cp public/stylesheets/scaffold.css tmp/war/stylesheets/scaffold.css
mkdir -p tmp/war/WEB-INF
- Deploy the WAR file ...
~/tools/jruby-1.2.0RC2/samples/rails/runner >~/tools/glassfish/v2.1/glassfish/bin/asadmin deploy runner.war
Command deploy executed successfully.
After adding few entries the page at "http://localhost:8080/runner/runners" looks like:
Later blogs will show the remainder of tests. The current set of tests are available using the tags rubyonrails+glassfish+integrationtest.
Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive of all tips is available here.
Technorati: totd rubyonrails glassfish v2 jruby warbler connectionpooling jdbc jndi integrationtest