4 minute read

Just for the posterity of the Internet, and because I didn’t find an immediately useful answer when searching with Google…

I’ve been looking at Groovy, a really cool language with similarities to Ruby and Smalltalk that runs as Java bytecode in a standard Java container, and Grails, which is the Groovy equivalent of Ruby on Rails – namely, a framework for quickly and easily creating web applications. Very neat stuff. I hope my interview this afternoon with the company using it goes well. :)

So, while reading up on Groovy and Grails I wanted to play with it on my Ubuntu Hardy laptop. I already had the sun-java6-jre package installed so I could do standard Java stuff. However, in order to publish a Grails application, which is required in order to run it, you need the JDK. So I also installed sun-java6-jdk. It’s possible I should have just removed the JRE and replaced it with the JDK, but the Ubuntu package manager didn’t complain, so I didn’t.

Doing a ‘which java’ pointed to /usr/bin/java, so I set my JAVA_HOME to /usr and move on to installing the rest. [at this point smart people may feel a tingling in their Spidey Sense]

I installed the Ubuntu groovy package, and downloaded the grails package and installed it with dpkg. Everything looks good, I can run ‘grails help’ from the command line without errors. So I create my grails app.

bryanf@ronin2:~$ grails create-app test

Welcome to Grails 1.0.3 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails

Base Directory: /home/bryanf
Note: No plugin scripts found
Running script /usr/share/grails/scripts/CreateApp.groovy
Environment set to development
    [mkdir] Created dir: /home/bryanf/test/src
    [mkdir] Created dir: /home/bryanf/test/src/java
    [mkdir] Created dir: /home/bryanf/test/src/groovy
    [mkdir] Created dir: /home/bryanf/test/grails-app
    [mkdir] Created dir: /home/bryanf/test/grails-app/controllers
    [mkdir] Created dir: /home/bryanf/test/grails-app/services
    [mkdir] Created dir: /home/bryanf/test/grails-app/domain
    [mkdir] Created dir: /home/bryanf/test/grails-app/taglib
    [mkdir] Created dir: /home/bryanf/test/grails-app/utils
    [mkdir] Created dir: /home/bryanf/test/grails-app/views
    [mkdir] Created dir: /home/bryanf/test/grails-app/views/layouts
    [mkdir] Created dir: /home/bryanf/test/grails-app/i18n
    [mkdir] Created dir: /home/bryanf/test/grails-app/conf
    [mkdir] Created dir: /home/bryanf/test/test
    [mkdir] Created dir: /home/bryanf/test/test/unit
    [mkdir] Created dir: /home/bryanf/test/test/integration
    [mkdir] Created dir: /home/bryanf/test/scripts
    [mkdir] Created dir: /home/bryanf/test/web-app
    [mkdir] Created dir: /home/bryanf/test/web-app/js
    [mkdir] Created dir: /home/bryanf/test/web-app/css
    [mkdir] Created dir: /home/bryanf/test/web-app/images
    [mkdir] Created dir: /home/bryanf/test/web-app/META-INF
    [mkdir] Created dir: /home/bryanf/test/lib
    [mkdir] Created dir: /home/bryanf/test/grails-app/conf/spring
    [mkdir] Created dir: /home/bryanf/test/grails-app/conf/hibernate
[propertyfile] Creating new property file: /home/bryanf/test/application.properties
     [copy] Copying 2 files to /home/bryanf/test
     [copy] Copied 1 empty directory to 1 empty directory under /home/bryanf/test
     [copy] Copying 2 files to /home/bryanf/test/web-app/WEB-INF
     [copy] Copying 5 files to /home/bryanf/test/web-app/WEB-INF/tld
     [copy] Copying 87 files to /home/bryanf/test/web-app
     [copy] Copying 18 files to /home/bryanf/test/grails-app
     [copy] Copying 1 file to /home/bryanf/test
     [copy] Copying 1 file to /home/bryanf/test
     [copy] Copying 1 file to /home/bryanf/test
     [copy] Copying 1 file to /home/bryanf/test
[propertyfile] Updating property file: /home/bryanf/test/application.properties

Created Grails Application at /home/bryanf/test

bryanf@ronin2:~$

Yay, it works!

Then I try to run my Grails app, using HTTPS because hey… it’s there.

bryanf@ronin2:~$ cd test
bryanf@ronin2:~/test$ grails run-app-https test

Welcome to Grails 1.0.3 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails

Base Directory: /home/bryanf/test
Note: No plugin scripts found
Running script /usr/share/grails/scripts/RunAppHttps.groovy
Environment set to development
    [mkdir] Created dir: /home/bryanf/.grails/1.0.3/projects/test/classes
  [groovyc] Compiling 6 source files to /home/bryanf/.grails/1.0.3/projects/test/classes
    [mkdir] Created dir: /home/bryanf/.grails/1.0.3/projects/test/resources/grails-app/i18n
[native2ascii] Converting 11 files from /home/bryanf/test/grails-app/i18n
  to /home/bryanf/.grails/1.0.3/projects/test/resources/grails-app/i18n

Error starting Sun's native2ascii:
bryanf@ronin2:~/test$

After several muttered curses and much searching around, I finally figured out the issue, extrapolated from all the search results saying “There’s something wrong with your JAVA_HOME”.

The way Ubuntu handles packages that may have overlapping commands is to setup a links in /usr/bin to files within /etc/alternatives, which are themselves links to places around the machine. The JRE apps link into /usr/lib/jvm/java-6-sun/jre/bin, while the JDK apps link into /usr/lib/jvm/java-6-sun/bin.

After setting JAVA_HOME to /usr/lib/jvm/java-6-sun, everything is happy.

bryanf@ronin2:~/test$ grails run-app-https test

Welcome to Grails 1.0.3 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails

Base Directory: /home/bryanf/test
Note: No plugin scripts found
Running script /usr/share/grails/scripts/RunAppHttps.groovy
Environment set to development
[native2ascii] Converting 11 files from /home/bryanf/test/grails-app/i18n
 to /home/bryanf/.grails/1.0.3/projects/test/resources/grails-app/i18n
     [copy] Copying 1 file to /home/bryanf/.grails/1.0.3/projects/test/classes
     [copy] Copying 1 file to /home/bryanf/.grails/1.0.3/projects/test/resources
     [copy] Copying 1 file to /home/bryanf/.grails/1.0.3/projects/test
2008-07-04 10:59:45.498::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
Creating SSL Cert...
Created SSL Cert
2008-07-04 10:59:46.283::INFO: jetty-6.1.4
2008-07-04 10:59:46.440::INFO: No Transaction manager found - if your webapp
 requires one, please configure one.
2008-07-04 10:59:52.760:/test:INFO: Set web app root system property:
 'test-development-0.1' = [/home/bryanf/test/web-app/]
2008-07-04 10:59:52.760:/test:INFO: Initializing log4j from
 [file:/home/bryanf/.grails/1.0.3/projects/test/resources/log4j.properties]
2008-07-04 10:59:52.787:/test:INFO: Initializing Spring root WebApplicationContext
[0] spring.GrailsWebApplicationContext Refreshing org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@1bc93a7:
 display name [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@1bc93a7];
 startup date [Fri Jul 04 10:59:53 EDT 2008];
 parent: org.springframework.web.context.support.XmlWebApplicationContext@fdb413
[0] spring.GrailsWebApplicationContext Bean factory for application context
 [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@1bc93a7]:
 org.springframework.beans.factory.support.DefaultListableBeanFactory@1c0ae76
2008-07-04 10:59:55.516:/test:INFO: Initializing Spring FrameworkServlet 'grails'
2008-07-04 10:59:56.611::INFO: Started [email protected]:8080
2008-07-04 10:59:56.910::INFO: Started [email protected]:8443

Server running. Browse to https://localhost:8443/test

Note: at this point all I’ve done is create the Grails application and run it, without adding any of my own code, and I have a running HTTPS application that will serve a static page. Cool beans.

This post was eventually useful in getting things working, though it’s a huge whack of text to plow through, and with several bits I didn’t really need. (do I need VNC instructions when talking about installing Grails?)

Now, back to reading more JavaOne presentations about Grails.