måndag, december 04, 2006

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!

1 kommentar:

ypt78 sa...

I did update the jruby-trunk that I have and recompiled with jdk1.5.
Then I tried
C:\rnd\jruby-trunk>jruby %JRUBY_HOME%\bin\gem install Camping --no-ri --no-rdoc
--include-dependencies


Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/ext/openssl
/RubyOpenSSL$Service
at org.jruby.Ruby.initLibraries(Ruby.java:545)
at org.jruby.Ruby.init(Ruby.java:501)
at org.jruby.Ruby.newInstance(Ruby.java:233)
at org.jruby.Main.runInterpreter(Main.java:146)
at org.jruby.Main.run(Main.java:111)
at org.jruby.Main.main(Main.java:86)

What can I do to fix it?