The Curse of Camping: The story continued


It’s time for another installment in the Camping saga. The last time I wrote about 1.5, and some things that didn’t work properly in JRuby. This time, the announcement is once again this: Camping 1.5 works in JRuby. It works very well, actually. To show this, I will make it very easy for you to follow along in how to achieve it.

First, have JRuby installed, either from trunk or version 0.9.2 if that version has been released when you read this.

Secondly, gem install ActiveRecord, Camping and all their requirements.

Thirdly, gem install ActiveRecord-JDBC.

Fourth, put you MySQL JDBC driver on your classpath (or any other JDBC driver you care to use).

Download blog.rb from the Camping examples here. Modify it by adding the line

require ‘jdbc_adapter’

after the other require’s at the head of the file.

Finally, you need to create a database file, since JRuby doesn’t support the standard choice of camping (which is SQLite3). To do this, create a file that’s named (on Linux) $HOME/.campingrc, or on Win32 %APPDATA%/Campingrc. (%APPDATA% is on most Win32-boxes something like c:\Documents and Settings\olagus\Application Data). This file should contain your database definition in standard ActiveRecord fare. My example looks like this:


database:
adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/blog
username: blog
password: blog

Of course, you should use your own individual settings and driver information.

Camping does only require that the database exists. It will add migrate the blog application automatically, and as soon as you’ve started the application by doing:

jruby $JRUBY_HOME/bin/camping blog.rb


it will listen on 3301 and be ready to serve an example blog application.

Have fun and enjoy!



JRuby versus Camping: Round 2


As undoubtedly some of you have discovered while trying, JRuby doesn’t run Camping anymore. The culprit is a small feature in Ruby that we don’t support yet. For some reason this feature is the preferred idiom for option parsing and Camping 1.5 introduced it, which means that Camping 1.5 will fail miserably in JRuby right now. There are more or less two ways around it, though. The first one is easy; just use a Camping version that is

opts.on("-p", "--port NUM", "Port for web server (defaults to #{conf.port})")
{ |conf.port| }

To fix this particular instance, just change it into this:

opts.on("-p", "--port NUM", "Port for web server (defaults to #{conf.port})")
{ |v| conf.port=v }

Not much of a difference, really. On all places where assignment to a non-obvious node is done in the manner above, just replace it with a regular assignment, and Camping will run.

Now, we are planning on fixing this syntax, but there is much development going down right now, and this change requires some changes in the parser, which is always interesting. But it will be there.