JRuby trunk – issues with JDBC connectivity


Following the book on JRuby I am discovering small differences when trying the examples. After installing activerecord-jdbc gem which is available in version 0.5, the shoplet application fails with Rails 2.0, as soon as you click on the ‘About your application environment’ link.

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.2 available at
** Use CTRL-C to stop.

Processing InfoController#properties (for at 2007-12-23 23:13:25) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--9791be23205677745e457b5bf62c50eba6e3813f
Parameters: {"controller"=>"rails/info", "action"=>"properties"}
Exception in thread "Ruby Thread11043409" java.lang.NoSuchMethodError: org.jruby.runtime.builtin.IRubyObject.setInstanceVariable(Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject;
at JdbcAdapterInternalService.set_connection(JdbcAdapterInternalService.java:122)
at JdbcAdapterInternalServiceInvoker$set_connection_FS1.call(Unknown Source)
at org.jruby.runtime.callback.FastInvocationCallback.execute(FastInvocationCallback.java:55)
at org.jruby.internal.runtime.methods.SimpleCallbackMethod.call(SimpleCallbackMethod.java:70)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:158)
at org.jruby.runtime.CallSite$ArgumentBoxingCallSite.call(CallSite.java:103)
at org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1092)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:345)
at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:626)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:293)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:168)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:147)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:158)
at org.jruby.runtime.CallSite$ArgumentBoxingCallSite.call(CallSite.java:76)
at org.jruby.evaluator.ASTInterpreter.vcallNode(ASTInterpreter.java:1734)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:474)
at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:626)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:293)
at org.jruby.evaluator.ASTInterpreter.rescueNode(ASTInterpreter.java:1499)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:442)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:168)

I found out that there is newer version of activerecord-jdbc, which is also renamed to activerecord-jdbc-adapter. It is important to uninstall the old gem as well as install the new one, otherwise the application will not work.

$ jruby -S gem install activerecord-jdbc-adapter
Successfully installed activerecord-jdbc-adapter-0.7
1 gem installed
Installing ri documentation for activerecord-jdbc-adapter-0.7...
Installing RDoc documentation for activerecord-jdbc-adapter-0.7...
$ jruby -S gem install activerecord-jdbcmysql-adapter
Successfully installed jdbc-mysql-5.0.4
Successfully installed activerecord-jdbcmysql-adapter-0.7
2 gems installed
Installing ri documentation for jdbc-mysql-5.0.4...
Installing ri documentation for activerecord-jdbcmysql-adapter-0.7...
Installing RDoc documentation for jdbc-mysql-5.0.4...
Installing RDoc documentation for activerecord-jdbcmysql-adapter-0.7...

$ jruby -S gem list activerecord

*** LOCAL GEMS ***

activerecord (2.0.2, 1.15.6)
ActiveRecord-JDBC (0.5)
activerecord-jdbc-adapter (0.7)
activerecord-jdbcmysql-adapter (0.7)

$ gem uninstall ActiveRecord-JDBC
Successfully uninstalled ActiveRecord-JDBC-0.5
miroslav-adamys-macbook-pro:shoplet miro$ gem list ActiveRecord-JDBC

*** LOCAL GEMS ***

activerecord-jdbc-adapter (0.7)
activerecord-jdbcmysql-adapter (0.7)

After this, everything works and shoplet connects to database – as you can see from the console log.

iPod Touch: which to choose – 8GB or 16GB ?


A friend asked me this question today – and here is my take on it (slightly expanded) answer to his email :-):

Hi Shane
I have purchased the 8 GB because I had no choice – the 16 GB versions were sold out at the Futureshop at the time, and I was too impatient to wait for two more weeks until delivered from Apple Online store :-).

From usage perspective – whether 8 GB is enough really depends how much video you plan to put on. I am not watching too much video content other than YouTube via WiFi (which is streamed and does not take any space on the device), so for me 8 GB is enough. Main reason why I am not watching video is that I usually listen while walking or driving and one cannot walk very far while concentrating on the screen without bumping into something (I tried that). With driving it is even worse (I did NOT try this one …). If you are willing to sit while watching, the image quality of the device is surprisingly good.

I usually carry 3-5 audiobooks on it (which adds up to about 2 GB), lots of podcasts (TWIT, Macbreak, Security Now, Windows Weekly, HanselMinutes, and few Ruby podcasts) which adds up to another gig or so – as I have only few last episodes to listen to.

In addition to that, I carry about 4 GB is music in case I need something for the treadmill or at work for background noise canceling. It works great. So far, even the most annoying/loud voice from cubicle next to me had not have any chance to compete with Rammstein :-). I found out that keeping about 0.5 – 1 GB free is good idea – in case there is larger chunk to sync. I also use the iTouch as PDA, but even with few hundreds contacts and calendar events, the size of data is very small.

Having 16 GB would only allow me to have more music – I cannot really subscribe to more audio podcasts because of time limits to listen and having more than 4-5 books adds little value. Even with 16 GB version I would not be able to have ALL my music with me – so the main advantage of not having to select which music you carry with you could not be achieved anyway.

But of course, YMMV – and if the above sounds like rather long rationalization of the choice I have already made and cannot change, well – maybe that is not quite wrong either. But it certainly makes me feel good about my selection :-). Besides the price difference between 8 GB and 16 GB is also a thing to consider.

From all the above it looks like 8 GB is sufficient and better deal than 16 GB. Right ? Well – there is a possible catch. When the new iPhone / iTouch SDK will be available (Jan/Feb 2008), it is VERY reasonable to expect that lots of new applications for iPhone/iTouch will be available soon. The most obvious choices will be an offline reader for PDF formats, mail program that will allow read and process your emails offline, News and Feeds offline readers and various forms of Google-gear like applications for various data management with disconnected mode and synchronization via iTunes/http+WiFi. All these have one in common: they will need and utilize local storage. With that in mind, maybe the additional 8 GB can be eventually very valuable and can make real difference how useful the gadget will be.

Your question about using for couple of hours without interaction – sure, no problem. Just make long enough playlist and you never have to touch your iTouch :-). Longest time I did that was 4 hour walk back in November, with only one break to pause it while buying coffee, so that I could understand what the friendly Timmi’s employee was asking.

Good luck with your choice. But I would still listen to Steve’s keynote first – 15th Jan is pretty close. Chances are there may be announced updated version of iPod for the same price – which usually causes price drop at the previous models.

Installation of Mongrel gem on JRuby


I bought the Ola Bini‘s eBook on JRuby and started to work through the examples. The installation of the Mongrel gem in JRuby (trunk revision 5341 fails with the following error code:

$ jruby -S gem install -y mongrel
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
Building native extensions.  This could take a while...
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
ERROR:  Error installing mongrel:
	ERROR: Failed to build gem native extension.

This error is logged in JIRA with id JRUBY-1771Workaround (possibly applicable for other gems is to explicitly specify the plaform:

$ jruby -S gem install -y mongrel --platform jruby
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
Successfully installed mongrel-1.1.2
1 gem installed
Installing ri documentation for mongrel-1.1.2...
Installing RDoc documentation for mongrel-1.1.2...

Fix for the stalled downloads in Leopard


I was experiencing the occasional weird behaviour on downloading large files in Leopard: the download would stall, but after stopping/restarting (which can be done in Safari and iTunes), the download would continue. It was not very consistent, and I suspected the NAT router or even Rogers – some sites were occasionally having this problem, while other sites would not.

While playing with JRuby over the weekend, this happened again and pretty much prevented the gem installation – because the multi-megabyte gem index would not download from http://gems.rubyforge.org/. Strangely enough, same download would work on Tiger, on Linux and on Windows using same router – which pretty much excluded router as a cause.

I found simple fix here – big thanks to Chris D Searle. Run the following:

sudo sysctl -w net.inet.tcp.rfc1323=0

(it replaces the default value of 1)

I do not know all the details of the fix – it switches off some TCP window optimization which may have been the cause of the problem. More on the parameter and how to set it in variety of OS-es can be found in the TCP tuning handbook.

To make change permanent, create (or edit) the file /etc/sysctl.conf with the content:


Joel’s gems


One of the most readable, original blogers out there, writing on software development practice and techniques – Joel Spolsky – published an excellent 3 part Talk at Yale: Part1, Part2 and Part3.

You will find out:

– what two computer science courses were most useful in his university studies
(one that was not really a comp-sci and one he decided to drop)
– why is it tough to be an in-house programmer
– why is the quality of many in-house systems so bad
– what is this “quality thing” anyway
– why is specification futile

Highly recommended.

Great Spring blog


in case you have not noticed – Interface21 aka SpringSource (great name change, btw) runs a blog with lots of hidden treasures inside.

Recent article describes new addition to Spring portfolio which is territory within my “watched space”: enterprise integration. See the blog entry for more.

If you are in corporate space that is keen on “standards”, the comparison of Spring vs EJB3 is very good article as well. Not that EJB would matter too much these days (IMHO) – but a nice read nevertheless.


An advice to a fellow developer – 2


The part 1 of the post is here.

— continuing —

So back again – different coffee shop (Starbucks at Carling), freshly charged battery, Grande Latte and no internet connection (which means no distractions from emails and the Web) – here we go again, part 2.

If I should single out one or two technologies that I think I have neglected and should have paid much more attention to it would be the Web trio of HTML/JavaScript/CSS as one and the SQL as second.

Let’s look at the Web trio first. It sounds weird – how can THIS be neglected, everybody knows HTML, right ? Wrong. What I mean is to have deep understanding of the HTML markup, so that you know when to use (and when not to use) tables, how to properly layout your page, fully understand the possibilities and implications of div and span, the box model and what can and cannot be done with styles and CSS. And I do not mean using Dreamweaver like tools or (god forbid) Frontpage to create the markup, I mean actually writing the markup. Ability to produce and maintain clean markup is very important for application lifecycle and evolution. Clean markup is at the beginning of every good looking site. Even if you get the first mockup version from your  designer, it is up to *you* to componentize the pages, convert them to JSP or ASP.NET or RHTML (or what server side stack you are using). And it is up to you not to mess it up in the process.

The CSS is trickier – it is considered to be “designer’s thing” between us, developers. And designers, they are those slightly weird artistic folks with Photoshop magic lassos and Macbooks that just somehow make things look great for no particular reason. They are so different species and us, developers who recognize 16 basic colors and do not mind using Times New Roman for everything will never be able to match their skills … This is partially true. It is hard to learn creative design. But even if you never will, it is still important to understand ENOUGH of CSS to know what can or cannot be done with it, so that you can maintain and enhance the design of the page without messing up the styles or the markup. You would not believe how big PITA it is to go through 100+ pages just to extract hard-coded font and size references, inserted there by the previous contractor who did not know any better … Do not do that to the guys that will maintain the app after you, it is very bad thing for your karma.

The HTML/CSS/JavaScript is also very important because it is the third platform, and despite JavaFX, SilverLight, Apollo and Flex flexing the muscles (pun intended) and a lot of buzz about the RIA, the traditional web technologies it is not going to go away any time soon. Listen to David H. Hansson interview for more. This stack is all you need to create Firefox extensions, new social network apps (like Facebook) and it will be important for the iPhone/iTouch and alike devices.

JavaScript is particularly tricky: the language itself is actually great and very powerful but got very bad reputation. Partly because it makes very easy to write very bad code, but mostly because many people using it have not enough experience or programming background and produce terrible mess. Not enough good books also contributes. I mean there are many books on JavaScript, but most of them bad or mediocre. We really need to learn or re-learn JavaScript and use it the proper way. I personally would pick JavaScript against Visual Basic any time.

The reason that I mention SQL is because most developers know just one part of it – how to select some data, insert or update. There is another part – that deals with creating tables, indexes etc and is usually “owned” by the professional DBA’s. Which is OK if you have one (and, btw, NEVER EVER trust a “DBA” that cannot create your database tables by ssh-ing to console on the server). In absence of dedicated database pros, many developers rely on GUI tools to get to initial stage of database structure, create tables, views etc. Problem in this that GUI tools cannot be version controlled and without having actual script that creates your database from scratch and loads all test data, your project environment is incomplete and you can never create good enough unit tests that will work. I have seen this to be an issue so many times that it is not even funny. Look at the migrations in Rails and how elegantly these guys solved the problem for Ruby world.

But enough about technologies, I’d like to add few closing more general remarks and mention some good books and sites.

Software development is a discipline somewhere between engineering and creative writing (it stubbornly resists applications of engineering methods like precise estimations :-)). Same as with writing, similar path will lead you to improvement of your skills. If you want to become great writer, read a lot. Read and dissect the text, think about the storyline, plot, setup, way how the dialogs are constructed and words used. If you want to become great developer, you also need to read a lot – not only books (we will get to that), but also code. Reading good code is crucial and is very intellectually stimulating. Reading means understanding how it is designed, thinking about the relations, architecture, idioms and noting nice tricks and howtos. As with literature, the ease of reading will depend on the language (you are native Java speaker) and your preferences / predispositions. In both cases it is important to select high quality reading material. Fortunately, that is easier that it looks like as with books because there is a consensus how should good code look like. In Java world, going through the source code of Spring Framework will teach you a lot. Look at the source code repositories that do some pre-selection of the projects such as CodeHaus rather than general sites such as SourceForge. For .NET world, look at the CodeProject, select one of the highly rated contributions and chances are very high that you will be OK.

Last but not least – few books and sites.

One great book that would be IMHO just right for where you are at is Refactoring from Martin Fowler. This is very easy way how get the spirit of the design patterns – IMHO better than reading the Gang of Four as the start – which is absolutely a great book to read, but maybe not the ideal to start with.

There few great books covering the “craft” of software development. The classic Pragmatic Programmer (which started the whole company) and Software Craftsmanship will give you more good advice on career of software developer than you may ever need :-). from Microsoft camp – even bigger classic  is Code Complete.

As for sites and blogs – there are way too many blogs and feeds of interest, email me, I will send you my blog feed from Google Reader. From programmer’s news I am keeping and eye on Dzone, InfoQ, TheServerside.com and theserverside.net. They may be not the best, but I found out that to actually get some time to do some coding and code reading, one must limit the news consumption …

Thats about it.

Happy coding, may the Source be with you 😉

PS: Thanks to all who managed to read until here and even bigger thanks for emails and comments to the part I. Your feedback is appreciated.