Friday, 30 July 2010

Grails one-liner package and install plugin

As we all know, running Grails with source plugins can cause a few oddities and many people prefer to run their plugins packaged. One bug I experienced on Grails 1.1 was uninstalling a source-linked plugin deleted the source code! Argh!

I was getting annoyed with having to have multiple terminal tabs open: one to package my plugin and another to install it, wait 3 seconds, type "y" and then to run my application. The command below solves my problems:

pushd ~/sites/plugin-a/; grails package-plugin; popd; yes | grails install-plugin ~/sites/plugin-a/; grails clean; grails run-app

I pipe "yes" to grails-install plugin; otherwise you'll be prompted to type "y" or "yes".

You can also combine these if you need to package multiple plugins.

pushd ~/sites/plugin-a/; grails package-plugin; popd; yes | grails install-plugin ~/sites/plugin-a/; pushd ~/sites/plugin-b/; grails package-plugin; popd; yes | grails install-plugin ~/sites/plugin-b/; grails run-app

It gets a little unreadable but can certainly save a lot of waiting/repeated typing.

Wednesday, 28 July 2010

Grails: Debugging GSPs: "errors at line [x]"

Debugging GSPs can be a right pain, especially with a heavily translated site: this often involves nesting g:messages inside virtually every other tag.

One of my annoyances was that the line numbers reported by the Grails parser were often wrong. "Error on line 430", it would say. "But my GSP only has 150 lines!" I shout back at my screen

I believe the problem is from nesting templates - when a GSP renders a template, that in turn renders a template, and so on - then the code grails generates is one file concatenated from each file that's been rendered.

So, how do you find where in your code things are going wrong? By appending ?showSource=true to your URL (or &showSource=true if you're passing in GET parameters). That's how.

This shows you Grails' generated file - I've found that the line numbers match, as you'd expect.

Increasing file handle limit in Ubuntu

I got the below error whilst trying to run my Grails application this morning:-

Caused by: error=24, Too many open files at java.lang.UNIXProcess.(

After a bit of digging around, it appears that some of the later versions of the Java JVM 1.6.+ are not closing unused file connections, which results in the default limit that is set for users in Ubuntu being hit and the above exception being thrown.

After searching the web I found the following solution.

To modify the limit for the current user session you can simply type the below into your bash terminal:-

$ulimit -n 2048

This will double the default value, but the changes will be lost upon restart of the machine.

To include a change in the system configuration, which will not be lost on restart, you will need to do the following:-

1. Edit limits.conf

$sudo gedit /etc/security/limits.conf

to include the line:

YourUser - nofile 51200

2. Update the common-session configuration

$sudo gedit /etc/pam.d/common-session

to include the line:

session required

Logout and log back in again and that should solve it.

Type "$ulimit -n" into a terminal and you should now see your new limit has been set, if not try giving the machine a restart.

Happy hunting...

Thursday, 8 July 2010

Keep it simple and staying up to date

Just watched a presentation on InfoQ

It reinforced a principle we try and adhere to on our applications - Keep it simple. We are very good at doing that as far as the user interface is concerned.

Aware Monitoring's have applied this to their development and makes design and technology choices based on their current skill set and limit the technologies they use.

This is certainly a very sound strategy for helping keeping complexity and cost under control, but this need to be balanced against the need to keep up to date and able to take advantage of new and emerging technologies. Without doing this you run the risk of being made obsolete by a someone using a new technology that makes them much more productive or changes the game in new unexpected ways.

We love technology and enjoy trying new technologies out. We perhaps need to evaluate how much this is costing us and make sure we have got the balance between "Keep it Simple" and staying up to date right for us.