Errors when setting up grails

I’m looking at Grails to explore how others set up REST architectures. Grails have built in support for REST using Hibernate and Spring. As such it seemed like an interesting development style to examine. Hibernate and nHibernate have similarities and Spring seems to be an interesting IoC framework.

But enough background, Ive been running Grails on my old desktop computer at home. This Friday I got a new laptop and I spent last night setting up my environment it. With Grails, the last thing I set up, I ran into a bunch of problems. In the end they were all my own fault, but I thought I’d blog about them. Since there weren’t much information on the subject last night.

First I downloaded Grails. To get it running I had to set up my environment variables. After setting JAVA_HOME and adding the JDK bin directory to my PATH. Grails attacked me with my first error.

C:\dev\grails-1.1\bin>grails The syntax of the command is incorrect

It turned out that my the bat files setting up the environment for Grails didnt set the GROOVY_HOME variable correctly, since my local variable for that contained spaces. Adding Quotes to the path gave this error instead.

C:\dev\grails-1.1\bin>grails Files was unexpected at this time

To solve that I downloaded and installed Groovy, after reading this old blog post.

Once I had Groovy installed, the path variables for GROOVY_HOME were all set. The installations sets the, even sets the PATH environment variables correctly. This resulted in the following error:

C:\dev\grails-1.1\bin>grails
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/grails/cli/support/GrailsStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.grails.cli.support.GrailsStarter
	at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: org.codehaus.groovy.grails.cli.support.GrailsStarter.  Program will exit.

The fix for the above error was to correct the GRAILS_HOME environment variable path. I had it set to the bin directory and not to the base directory of the Grails installation.

Now I have Grails up and running