Thursday, March 25, 2010

Upgrading and Deploying GQuick Code

Several people have gone through the sample application from GQuick using more recent versions of Grails (1.2 and 1.2.1), and it all seems to work, with one exception. If you use packages, as Grails 1.2 and above encourage you to do, one of the plugins (the Blurb plugin) will fail. I've been in contact with the plugin's author and he promises to fix that soon.

On the other hand, if you didn't build the TekDays application but would like to work with the code downloaded from the Pragmatic Programmer's website, there is a different issue. I recently downloaded the final code base, which is found in the download bundle at code/deploy/TekDays/, and upgraded it to Grails 1.2.1. I ran into a conflict with two versions of the Bubbling plugin. It appears that the upgrade process pulls down the newer version of the Bubbling plugin (2.1.1), but the old version (1.5.1) was still installed. The solution (or at least a solution) was to go to home/.grails/1.2.1/projects/TekDays/plugins/and remove the 1.5.1 version of the plugin. After that it all worked fine.

It worked fine, that is, until I tried to deploy the app to Tomcat. When I built the .war file and copied it to my /webapps/ directory, it wouldn't start. I tried forcing it to start from the Tomcat manager. No dice. So I checked in /logs/catalina.out (if you're using Tomcat, you gotta love that file), and found a datasource error that made me smack my forehead.

In the last chapter of GQuick, we look at how to configure a Grails application to use a JNDI datasource, which is a good idea for a real production deployment. But you may not have JDNI configured on your local Tomcat instance; I sure didn't. So, I changed my grails-app/conf/DataSource.groovy file to make the production datasource the same as development.

If you are doing this for the first time and haven't worked through the book, you will need to create a MySQL database called tekdays and set the user and password to match that in the DataSource.groovy file (or vice versa). Alternatively, you can use any database with a JDBC driver. Just include your JDBC driver in the TekDays/grails-app/lib/ directory and modify your DataSource.groovy accordingly. I prefer MySQL because it's so easy to get and easy to use. (More info on MySQL can be found at http://dev.mysql.com.)

One final note: Some people have mentioned getting OutOfMemoryErrors when deploying the app to Tomcat. This can happen with any Grails app if the JVM memory settings are too low. To prevent this, you can add (or modify) a JAVA_OPTS environment variable. In Linux/Unix or Mac OSX, you could do something like this:

export JAVA_OPTS='-Xmx1G -XX:MaxPermSize=256m'

In Windows, you can use the wizard in the control panel under System. Or maybe you can edit your autoexec.bat file. (Do they still use that?)

For the best learning experience, it's probably worth the time to go through the book and build the app as you go, but if you want to just download it and take it for a spin first, these tips should help you get going.

Have fun!

8 comments:

  1. This is really helpful! Thanks dave!

    ReplyDelete
  2. Just what I was searching for...
    The problem with the Blurb plugin is that the Blurb classes are in the default package, and cannot be accessed from a class within a package. Yuck!

    ReplyDelete
  3. I must be the Grails dummy all-time. I have your book and have read your blog some especially this entry. And, I fail to see how to run the individual example code snippets while reading along in your book? I have created a Grails project named: dkgrails and untarred the tarball to the /code directory. I'm using Netbeans 6.9 that is very good at recognizing Grails projects w/o doing anything more than navigating the NB file browser to the directory location of the target Grails project. Unfortunately, my instance of NB does not recognize your untarred /code directory as a Grails project?

    I suppose my question is do I need to create a whole new Grails project named: tekdays? and piece together the project as I read along in your book? Or, have I not read far enough?

    I tried using the Grails command-line interactive but this too fails to run any of the snippets. Baffling.

    Please advise, David.

    ReplyDelete
  4. @induction:

    Creating a new TekDays project at the beginning and adding to it as you go through the book is the recommended strategy. However the code in the download should run after following the steps in this post.

    One thing to note is that the complete project is in the tarball multiple times. Under the code directory there should be one or more directories for each chapter. Inside each of those directories is a TekDays directory. This will contain the entire project as it was at that stage of the book. If that's not what you are seeing, please let me know. You can also reach me via email. My address is in the appendix at the back of the book.

    Thanks,
    Dave

    ReplyDelete
  5. Hello Dave, thanks much for this. Netbeans has the feature of recognizing a Grails project just by using the file browser. I now can match up my reading with Model1, Model2, ... I must say that using the PDF download links was working and forcing me to work through the pages hands-on step at a time. Now, I think I can move faster with the tarball code. Gr8! And, thanks again, David.

    ReplyDelete
  6. Hello Dave, the Model1 TekDays Grails app builds but when it deploys my browser displays 404:
    The requested resource (/TekDays/WEB-INF/grails-app/views/index.jsp) is not available. Particulars follow:
    OS: Ubuntu 9.10
    Browser: FireFox
    Grails: 1.3.2
    JDK: 1.6.0

    ReplyDelete
  7. Hello Dave, sorry about all the noise: I found the /ourproject/tekdays version (using mysql btw) and voila! I'm up-and-running with a real go-by while I read. Thanks for a gr8 leg-up type book! I'm a 12 year Java programmer (yes, 1998) with no Groovy background but I seem to get it now. Like you I have wasted a good deal of my career on EJBs and monsters like Weblogic and JBoss. FWIW: I have upgraded TekDays to: 1.3.2. Thanks for the salvation, David.

    ReplyDelete
  8. Hi David,

    Glad you got it working and welcome to the family! :)

    ReplyDelete