JRuby: Wiki: RailsWithH2InJNDIOnJetty — Project Kenai
This page is grossly out of date
In order to have an H2 database in a file be accessible from a web server it in necessary to configure the webserver for JNDI. Here we use warbler to create a war from an existing rails app and deploy it on Jetty.
1. Install h2 adapter and warbler
These instructions don't appear to work with warbler 0.9.9.
2. Create production database and run migrations
I'm not sure what the most elegant way to do this is. One way is to edit the database.yml file before creating the database to make it easy to create the database and then modify it again before creating the .war file. In my case, I simply set the name of the development database to the name of the production database.
To do so, edit database.yml as follows:Run
3. Create and edit warble.rb
Run
This will create a config/warble.rb file.
At about line 36 of this file addand be sure that the line.
is not commented out.
Near the bottom of the file uncomment and edit the line with config.webxml.jndi
Note: I had better luck with this when the value did not include a slash. "rails/db" for example didn't work.
4. Create war file.
Run
5. Configure Jetty
Unzip your Jetty download to JETTY_HOME. Copy GEM_HOME/jdbc-h2-1.0.63/lib/h2-1.0.63.jar to JETTY_HOME/lib. In order to enable JNDI, the jetty-plus configuration has to be set up. One way to do this is to uncomment lines 57-71 in JETTY_HOME/etc/jetty-plus.xml. Another way would be to create another configuration file following JETTY_HOME/etc/jetty.xml and adding the configuration classes in JETTY_HOME/etc/jetty.xml. If you go the route of uncommenting the lines in jetty-plus.xml, you will need to create a directory JETTY_HOME/webapps-plus and put your war file there.
You will also need to add the jndi data source, for example by adding a file called my_jetty.xml.
6. Run the Jetty web server
In the scenario described in step 5 this would be.
This will start the application at localhost:8080/my_app_name:
Clearly, "my_app_name", "my_username", "my_password", "c:/db/my_database_name" and "my_db" should be replaced throughout with the appropriate values.