Friday, 8 April 2011

Grails - Ruby on Rails for the JVM

This post will be about a framework for the JVM called Grails, which stands for (or rather, used to stand for) Groovy on Rails. Grails is a RoR-like framework making use of the Groovy language and the "Convention over Configuration" paradigm which RoR seems to have made so popular.

First a little bit of history as to how I discovered grails. I was introduced to the grails framework in a round about way, when I started looking for the perfect RoR IDE and ended up using Netbeans (funnily enough, Netbeans has since dropped support for RoR). As a way of getting familiar with Netbeans I started working my way through the Netbeans tutorials, trying out the different frameworks and technologies along the way. This eventually led me to Grails. If there's one thing to be taken away from this little story it's to never stop learning new ways to write code and that the Netbeans tutorials are an excellent resource :-)

So, to get on with the show. We will be using a clean install of Ubuntu 10.10 (desktop edition) as our operating system, so bear in mind that you may have to tweak the commands below depending on your enviroment. The first thing we need to do before installing grails is to ensure that we have a Java runtime environment and a Java Developement Kit installed. Ubuntu 10.10 should come with the OpenJDK JRE installed by default. To check this out we open a terminal run java -version and we should see the following as output:

java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1)
OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)


To install the JDK, we run:

sudo apt-get install openjdk-6-jdk

and install all of the necessary packages.

In order to run grails from the command line, we'll also need to set the JAVA_HOME and GRAILS_HOME variables as well as adding these to the PATH. We can achieve this by adding the following to the bottom of our ~/.bashrc file:

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export GRAILS_HOME=$HOME/grails
PATH=$PATH:$JAVA_HOME/bin:$GRAILS_HOME/bin


NOTE: We'll have to open a new console window for these environment variables to become available.

Now that we've setup the environment, we can go to grails.org and download the latest Grails binary (1.3.7 at the time of this article). I usually move it to the home folder so that it's sitting under ~/grails-1.3.7. The observant amongst you will have noticed that in our ~/.bashrc file we've set $GRAILS_HOME to ~/grails previously, so in order to make this work, we create a symbolic link to this folder using ln -s ~/grails-1.3.7 ~/grails. We should now have our grails environment set up, so running grails from the terminal should give the following output:

Welcome to Grails 1.3.7 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /home/srdan/grails

No script name specified. Use 'grails help' for more info or 'grails interactive' to enter interactive mode


Congratulations, we now have a working grails install!

That's it for this post, in the next one we'll be having a look at creating our first grails project.

Tuesday, 29 March 2011

Book Review: Version Control with Subversion

I just finished reading the online version of the Version Control with Subversion book, which is available for free at the link provided. The book was an incredible help in teaching me the ins and outs of subversion. The only thing I can say that was perhaps not as great as it should have been is that it sometimes went into too much detail, exploring too many of the options and fringe use cases.

While I have managed to set up a repository, make it available over WebDAV and have a Redmine install use it, all without having read this book, this was mostly done by following a recipe. This means that I didn't delve too much into the workings of the software or all of the different configurations that you could have. This area is where this book shines. It tells you how you could have done things differently and the possible reasons for doing so. I personally found several configuration options which I have tweaked on my own Subversion/Apache setup to make it more secure and efficient.

Overall, a good read and while I can't say for sure that everything in this book will be relevant to you, I can say for sure that nearly everyone using Subversion will find something in this book for them.

Monday, 21 March 2011

Eclipse IDE indentation shortcut

If you're editing some code in Eclipse and you want to indent it, you just select the block of code and hit the TAB key. But what about if you want go go back the other way? In this case, you just use Shift+TAB.

Simple really, not sure why they don't have the keyboard shortcut listed next to the menu option to do the same thing.

Saturday, 5 March 2011

Changing JRE's in Ubuntu

If you're working with Java on Ubuntu, you have two main choices as to which runtime to use. The open source OpenJDK and the official Sun runtime. Luckily, due to the alternatives system in Ubuntu (probably inherited from Debian) you can install both of these and switch between them as you see fit.

To see your currently installed JRE's run the command:

$ update-java-alternatives -l

and you should see some output like:

java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun


This assumes that you've installed both of the runtimes. If you've only got one or the other installed, you will only see one line in the above output.

Now that we know which runtimes are installed, it would also be nice to be able to see which one we are using at the moment. Run the command:

$ java -version

If you see the ouput:

java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)


Your are running the OpenJDK runtime. If you see:

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)


You are running the Sun runtime. As an aside, the OpenJDK version is generally always a few versions behind the official Sun version.

So now that we know which runtimes we have installed and which one we are using at the moment, we can finally switch between them, using the update-java-alternatives command.

To switch to Sun's JRE:

sudo update-java-alternatives --set java-6-sun

To switch to OpenJDK:

sudo update-java-alternatives --set java-6-openjdk

To learn about the OpenJDK project and how it differs from the Sun Java runtime, you can have a look at:

http://openjdk.java.net/
http://en.wikipedia.org/wiki/OpenJDK

The 'update-java-alternatives' command has a lot more options allowing you to choose to switch just the JRE (and keep the JDK the same), or only switch out the browser plugin. To see all of the alternative options, have a look at the man page 'man update-java-alternatives'.

Wednesday, 16 February 2011

Installing from URL on Citirx XenServer

Citirx XenServer has a nice feature which lets you install a Linux directly from the repository. The one catch is that you have to get the URL right and if you don't you only get the error when you try and start up the VM. I've only tried out CentOS and Debian, the URL's for these distros are:

http://ftp.ca.debian.org/debian/ (Debian)

http://mirror.csclub.uwaterloo.ca/centos/5.5/os/x86_64/ (CentOS)

Note that since our host server is in Canada, I have used the Canadian mirrors. If you're using a different mirror, you'll have to replace the hostname with the hostname of your mirror.

Tuesday, 15 February 2011

How to change timezone on RHEL/CentOS

Here’s how to change the timezone on CentOS/RHEL:

cp /usr/share/zoneinfo/Pacific/Auckland /etc/localtime

Tuesday, 8 February 2011

Installing Redmine + SVN on Ubuntu 10.04

I've got a new workstation pc. It's not much (no hardware supported virtualization, onboard graphics) but it does the job. I've decided to take it and basically turn it into the ultimate development machine. That is to say, start right from the beginning and do things properly. The last sentence probably means a lot of different things to a lot of different programmers, so what does it mean to me? Well basically:

* Ability to access the machine remotely (Dynamic DNS + SSH/Web access)
* A Version Control System (Subversion, thank you very much)
* Project management/issue tracking software
* Development web server + database (Tomcat & MySQL)

So, today I will be writing how to get Subversion + Redmine up and running on Ubuntu 10.04. Partly to help someone out there that might be having the same problem and partly because I'll probably be having to install it again in the future and having a written record might save some time :-)

I've installed both Subversion and Redmine from the repositories and generally used the sample configuration which came with the packages, with a little bit of tweaking of course.

Installing Subversion is as easy as running:

sudo apt-get install subversion libapache2-svn

Next, I mostly followed the subversion install instructions found on the ubuntu wiki page, setting up a private repository. The wiki writeup is excellent, telling you how to get up and running quickly, whether you use subversion over HTTP/HTTPS/SVN/SVN+SSH.

Redmine was a little more tricky to install, although still a lot easier than I remember it being before it was in the repositories. Start by running:

sudo apt-get install redmine redmine-mysql

If you don't use MySQL, use one of the alternates (redmine-sqlite, redmine-pgsql). The sample configuration for Apache can be found at /usr/share/doc/redmine/examples/. I used the 'apache2-alias.conf' file by pasting it into /etc/apache2/sites-available/redmine and running:

sudo a2ensite redmine
sudo /etc/init.d/apache2 restart

After this I got an error saying that one of the apache directives was in the wrong place:

... waiting Syntax error on line 14 of /etc/apache2/sites-enabled/redmine:
SocketPath cannot occur within section


I then tried moving the directive to the /etc/apache2/mods-available/fcgid.conf, however this ended up giving me a different set of errors in the apache error log:

[Sun Feb 13 16:23:33 2011] [error] (13)Permission denied: mod_fcgid: couldn't bind unix domain socket /var/run/redmine/sockets/default/6126.28
[Sun Feb 13 16:23:33 2011] [warn] (13)Permission denied: mod_fcgid: spawn process /usr/share/redmine/public/dispatch.fcgi error

Finally, I commented this line out from both sections and was able to get redmine going without fcgi (Later I realised that I had installed passenger and it was running and that this was probably the reason that fcgi kept throwing the errors.

So, then you can navigate to http://localhost/redmine/ and configure the admin user (default username/pass is admin:admin) and you should have a working Redmine install.