<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>REVERT TO CONSOLE &#187; Groovy</title>
	<atom:link href="http://www.reverttoconsole.com/blog/category/groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reverttoconsole.com</link>
	<description>for f in *;do echo &#124; sed 'i\rtc' &#62;&#62; $f;done;</description>
	<lastBuildDate>Sat, 10 Jul 2010 12:40:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The Thoughtworks Rover Problem &#8211; Groovy Edition</title>
		<link>http://www.reverttoconsole.com/blog/groovy/the-product-of-scorn/</link>
		<comments>http://www.reverttoconsole.com/blog/groovy/the-product-of-scorn/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 18:43:46 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://www.reverttoconsole.com/?p=542</guid>
		<description><![CDATA[I had some down time at work, and set about working on the Rover problem. There are three problems, I chose the middle one to start with. I wrote it in groovy and used the very groovy clibuilder M. Laforge recommended in his comment. I mavenized it to make it easier to share. You can [...]]]></description>
			<content:encoded><![CDATA[<p>I had some down time at work, and set about working on <a href="http://www.technicalypto.com/2010/02/thoughtworks-mass-rovers-coding-problem.html">the Rover problem</a>.</p>
<p>There are three problems, I chose the middle one to start with. I wrote it in groovy and used the <a href="http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/">very groovy clibuilder M. Laforge recommended in his comment</a>. I mavenized it to make it easier to share.</p>
<p>You can find my solution <a href="http://github.com/ehemminger/groovy-rover">here </a>if you&#8217;re interested. It&#8217;s a good practice problem.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F&amp;title=The+Thoughtworks+Rover+Problem+%26%238211%3B+Groovy+Edition" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F&amp;title=The+Thoughtworks+Rover+Problem+%26%238211%3B+Groovy+Edition" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F&amp;title=The+Thoughtworks+Rover+Problem+%26%238211%3B+Groovy+Edition" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F&amp;title=The+Thoughtworks+Rover+Problem+%26%238211%3B+Groovy+Edition" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F&amp;title=The+Thoughtworks+Rover+Problem+%26%238211%3B+Groovy+Edition', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F&amp;title=The+Thoughtworks+Rover+Problem+%26%238211%3B+Groovy+Edition" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fthe-product-of-scorn%2F&amp;title=The+Thoughtworks+Rover+Problem+%26%238211%3B+Groovy+Edition" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/groovy/the-product-of-scorn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing Grails Apps in Eclipse</title>
		<link>http://www.reverttoconsole.com/blog/grails/developing-grails-apps-in-eclipse/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/developing-grails-apps-in-eclipse/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:11:53 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://www.reverttoconsole.com/?p=368</guid>
		<description><![CDATA[This was a post I was planning on linking to; a colleague of mine was going to write a post about it, but he hasn&#8217;t yet and I&#8217;ve just spent an extra hour trying to get this to work and am frustrated- and so here is the post you&#8217;ve all been waiting for. There are [...]]]></description>
			<content:encoded><![CDATA[<p>This was a post I was planning on linking to; a colleague of mine was going to write a post about it, but he hasn&#8217;t yet and I&#8217;ve just spent an extra hour trying to get this to work and am frustrated- and so here is the post you&#8217;ve all been waiting for.</p>
<p>There are lots of holes in the existing documentation about setting up eclipse to work with grails.</p>
<p>First off, you will want to generate groovy class files to a directory, like bin-groovy. It&#8217;s not just for debugging, it&#8217;s also for running unit tests. Running unit tests from eclipse is a lot faster than running them from the command line, because eclipse will generate the class files needed as you develop. It&#8217;s really nice to have.</p>
<p>Here&#8217;s where the fun starts- let&#8217;s assume you want to use a plugin. It&#8217;s a reasonable assumption, since there are so many cool plugins available. The first thing you need to know is where plugins download and install to. These go to a plugin directory in your .grails directory, which is normally in your home folder. You&#8217;ll need the jars from these plugins in your eclipse classpath, so you&#8217;ll need to unzip them and add them as external jars. Then, you&#8217;ll also need the source from those plugins in your classpath. For this, I added an External Class Folder to my Java Build Path- the folder was located in .grails/projects/<my project>/classes.</p>
<p>While you&#8217;ll want to uncheck the Disable Groovy Compiler Generating Class File checkbox, you&#8217;ll want to enable the Disable Check Package Matches Source Directory, otherwise you&#8217;ll have a compiler error from resources.groovy.</p>
<p>Finally, add bin-groovy as a class folder to your java build path libraries tab.</p>
<p><a href="http://enterprisejavatechblog.blogspot.com/2008/12/unit-testing-grails-in-eclipse.html">This entry was a big help</a>.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgrails%2Fdeveloping-grails-apps-in-eclipse%2F&amp;title=Developing+Grails+Apps+in+Eclipse" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/developing-grails-apps-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Dirt Simple EXTJS Grid on Grails</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/dirt-simple-extjs-grid-on-grails/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/dirt-simple-extjs-grid-on-grails/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 21:37:53 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/?p=223</guid>
		<description><![CDATA[At my current contract, I&#8217;ve been using the popular EXTJS javascript library. In order to get up to speed faster, I&#8217;ve started a small project to assist my learning. I thought about using a number of back ends to support my project, but decided on Grails after reading about the built-in JSON converters. Getting started [...]]]></description>
			<content:encoded><![CDATA[<p>At my current contract, I&#8217;ve been using the popular <a href="http://extjs.com/">EXTJS </a>javascript library. In order to get up to speed faster, I&#8217;ve started a small project to assist my learning.</p>
<p>I thought about using a number of back ends to support my project, but decided on Grails after reading about the built-in JSON converters.</p>
<p><strong>Getting started note</strong>: Since this is a dirt simple example, I copied extjs into the web-app/js directory. <a href="http://jlorenzen.blogspot.com/2008/08/getting-started-with-grails-and-extjs.html">James Lorenzen looks like he has a better way</a>, and there <a href="http://grails.org/Ext+Plugin">might be a plugin some day</a>.</p>
<p>I started with a simple GORM object, Media, which looks like this:</p>
<pre class="brush: java">
class Media {

	static constraints = {
		releaseDate(nullable: true)
	}

	String title
	Date releaseDate
	Date dateCreated
	Date lastUpdated
}
</pre>
<p>Next I added some startup data by adding it to to Bootstrap.groovy class:</p>
<pre class="brush: java">
     	def m = new Media(releaseDate:null, title: &#039;Test&#039;)
     	m.save()
</pre>
<p>And added a controller:</p>
<pre class="brush: java">
import grails.converters.*

class MediaController {

    def view = {

    }

    def list = {
   	def listResult = [ total: Media.count(), items: Media.list(params)]
        render listResult as JSON
    }
}
</pre>
<p>And I now have a Grails back end that will deliver JSON to extjs! Off to the front end!</p>
<p>First I modified my layout, main.gsp, to add the extjs js and css files:</p>
<pre class="brush: html">
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;g:layoutTitle default=&quot;Grails&quot; /&gt;&lt;/title&gt;

		&lt;link rel=&quot;stylesheet&quot; href=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/resources/css/ext-all.css&#039;)}&quot;&gt;&lt;/link&gt;
		&lt;link rel=&quot;stylesheet&quot; href=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/resources/css/theme-aero.css&#039;)}&quot;&gt;&lt;/link&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/adapter/ext/ext-base.js&#039;)}&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/ext-all-debug.js&#039;)}&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
			Ext.BLANK_IMAGE_URL = &quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/resources/images/default/s.gif&#039;)}&quot;;
		&lt;/script&gt;
		&lt;g:layoutHead /&gt;

	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;container&quot;&gt;
			&lt;div id=&quot;content&quot;&gt;
				&lt;div id=&quot;include&quot;&gt;
					&lt;g:layoutBody /&gt;
				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>and added my view.gsp:</p>
<pre class="brush: html">
&lt;html&gt;
	&lt;head&gt;
		&lt;meta name=&quot;layout&quot; content=&quot;main&quot; /&gt;
		&lt;title&gt;Decorated&lt;/title&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;oscar.js&#039;)}&quot;&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;center-div&quot;&gt;&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>and lastly, my js file, taken nearly verbatim from an extjs example:</p>
<pre class="brush: javascript">
/*
 * Ext JS Library 2.0 Beta 1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 *
 * http://extjs.com/license
 */

Ext.onReady(function(){

    // create the Data Store
    var ds = new Ext.data.Store({
       autoLoad: true,
       proxy: new Ext.data.HttpProxy({
       url: &#039;http://localhost:8080/oscar/media/list&#039;}),
       reader: new Ext.data.JsonReader({
       	results: &#039;total&#039;,
       	root:&#039;items&#039;,
       	id:&#039;id&#039;
       },
       [
               {name: &#039;title&#039;},
               {name: &#039;dateCreated&#039;},
               {name: &#039;lastUpdated&#039;},
               {name: &#039;releaseDate&#039;}
          ]
       )
    });

    var cm = new Ext.grid.ColumnModel([
	    {header: &quot;Title&quot;, width: 120, dataIndex: &#039;title&#039;},
		{header: &quot;Created Date&quot;, width: 180, dataIndex: &#039;dateCreated&#039;},
		{header: &quot;Last Updated&quot;, width: 115, dataIndex: &#039;lastUpdated&#039;},
		{header: &quot;releaseDate&quot;, width: 100, dataIndex: &#039;releaseDate&#039;}
	]);
    cm.defaultSortable = true;

    // create the grid
    var grid = new Ext.grid.GridPanel({
        ds: ds,
        cm: cm,
        renderTo:&#039;center-div&#039;,
        width:540,
        height:200
    });
});
</pre>
<p><a href="http://svn.reverttoconsole.com/rtc/oscar/">My code is checked in here</a>.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/dirt-simple-extjs-grid-on-grails/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Groovy Environment Scripting</title>
		<link>http://www.reverttoconsole.com/blog/groovy/groovy-environment-scripting/</link>
		<comments>http://www.reverttoconsole.com/blog/groovy/groovy-environment-scripting/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 20:30:08 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/?p=201</guid>
		<description><![CDATA[Problem: You want to use groovy all the time, but ignorant (but paying) forces keep you writing verbose tedious Java code instead. Solution: Use groovy instead of shell scripts! In large Java development projects, developing in a local environment comes with a maddening list of pulling levers, pushing buttons, and spinning wheels. Many of these [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> You want to use groovy all the time, but ignorant (but paying) forces keep you writing verbose tedious Java code instead.</p>
<p><strong>Solution:</strong> Use groovy instead of shell scripts! In large Java development projects, developing in a local environment comes with a maddening list of pulling levers, pushing buttons, and spinning wheels. Many of these can be automated with scripts, and those that can can be Groovy scripts.</p>
<p>I wrote this script to clean up after <a href="http://www.liferay.com/web/guest/home">liferay portal</a> kruft:</p>
<pre class="brush: java">
#!/usr/bin/env groovy

class Build{
    def ant = new AntBuilder()
    def localhostDir = &quot;C:/dev/liferay/tomcat/work/Catalina/localhost&quot;
    def portraitDir = localhostDir + &quot;/portrait&quot;
    def liferayDir = &quot;C:/Documents and Settings/ujxh744/liferay&quot;
    def luceneDir = liferayDir + &quot;/lucene&quot;
    def classpath = ant.path {
        dirset(dir: liferayDir){
            include(name: &quot;*&quot;)
        }
        dirset(dir: localhostDir) {
            include(name: &quot;*&quot;)
        }
   }

    void cleanUpLiferayShit() {
        ant.delete(dir: portraitDir)
        ant.delete(dir: luceneDir)
    }

    void echoDirectories(dirPath) {
        def pathList = dirPath.list()
        println &quot;There are &quot; + dirPath.size() + &quot; remaining directories&quot;
        dirPath.list().each{ arg -&gt;
            println arg
        }
    }
}

def b = new Build()
b.cleanUpLiferayShit()
b.echoDirectories( b.getClasspath())
</pre>
<p>Reference Links:<br />
<a href="http://www.javaworld.com/javaworld/jw-10-2004/jw-1004-groovy.html">Javaworld</a><br />
<a href="http://groovy.codehaus.org/Using+Ant+from+Groovy">Groovy Ant site</a></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F&amp;title=Groovy+Environment+Scripting" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F&amp;title=Groovy+Environment+Scripting" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F&amp;title=Groovy+Environment+Scripting" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F&amp;title=Groovy+Environment+Scripting" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F&amp;title=Groovy+Environment+Scripting', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F&amp;title=Groovy+Environment+Scripting" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-environment-scripting%2F&amp;title=Groovy+Environment+Scripting" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/groovy/groovy-environment-scripting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Grails Extended ManyToMany GORM Example</title>
		<link>http://www.reverttoconsole.com/blog/grails/grails-manytomany-gorm-example/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/grails-manytomany-gorm-example/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 02:51:47 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/194</guid>
		<description><![CDATA[This is a variation on this article. Having never been a big fan of writing XML, I&#8217;ll gladly opt for the XML-less version. The first example online I found has some formatting issues and just seems a little hard to follow. My step by step example follows after the jump. Call it the &#8220;Grails extended [...]]]></description>
			<content:encoded><![CDATA[<p>This is a variation on <a href="http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML">this article</a>. Having never been a big fan of writing XML, I&#8217;ll gladly opt for the XML-less version. <a href="http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML">The first example online</a> I found has some formatting issues and just seems a little hard to follow.</p>
<p>My step by step example follows after the jump. Call it the &#8220;Grails extended many-to-many step-by-step guide using the grails console, for dummies&#8221;.</p>
<p><span id="more-164"></span></p>
<p>Let&#8217;s start with a very simple example:</p>
<blockquote><p>A person has one or more characteristics. A characteristic can be applied to more than one person. A PersonCharacteristic relationship has an assignedValue.</p></blockquote>
<p>Here&#8217;s what I did:</p>
<pre>
<code>
grails create-domain-class person

grails create-domain-class characteristic

grails create-domain-class personCharacteristic
</code>
</pre>
<p>First I fleshed out Person:</p>
<pre class="brush: java">
class Person {

	static hasMany = [characteristics:PersonCharacteristic]

	String firstName
	String lastName

	List characteristics() {
		return characteristics.collect{it.characteristic}
	}

	List addCharacteristic(Characteristic characteristic) {
		return addCharacteristic(characteristic, new Integer(1))
	}

	List addCharacteristic(Characteristic characteristic, Integer assignedValue) {
		PersonCharacteristic.link(this, characteristic, assignedValue)
		return characteristics()
	}

	List removeFromCharacteristics(Characteristic characteristic) {
		PersonCharacteristic.unlink(this, characteristic)
		return characteristics()
	}

}
</pre>
<p>and Characteristic is pretty similar</p>
<pre class="brush: java">
class Characteristic {

	static hasMany = [people:PersonCharacteristic,employers:EmployerCharacteristic]

	String name
	String description
	Integer systemWeight = new Integer(1)

	List people() {
		return people.collect{it.person}
	}

	List employers() {
		return employers.collect{it.employer}
	}

	List addToEmployers(Employer employer) {
		EmployerCharacteristic.link(employer, this)
		return employers()
	}

	List addToPeople(Person person) {
		PersonCharacteristic.link(person, this)
		return people()
	}

	List removeFromEmployers(Employer employer) {
		EmployerCharacteristic.unlink(employer, this)
		return employers()
	}

	List removeFromPeople(Person person) {
		PersonCharacteristic.unlink(person, this)
		return people()
	}
}
</pre>
<p>and finally, PersonCharacteristic</p>
<pre class="brush: java">
class PersonCharacteristic {

	def Person person
	def Characteristic characteristic
	def Integer assignedValue

	static PersonCharacteristic link(Person person, Characteristic characteristic) {

		return link(person, characteristic, new Integer(1))
	}

	static PersonCharacteristic link(Person person, Characteristic characteristic, Integer assignedValue ) {
		def pc = PersonCharacteristic.findByPersonAndCharacteristic(person, characteristic)
		if (!pc) {
			pc = new PersonCharacteristic(userWeight:1)
			pc.person = person
			pc.characteristic = characteristic
			pc.assignedValue = assignedValue
			person?.addToCharacteristics(pc)
			characteristic?.addToPeople(pc)
			pc.save()
		}
		return pc
	}

	static void unlink(Person person, Characteristic characteristic) {
		def pc = PersonCharacteristic.findByPersonAndCharacteristic(person, characteristic)
		if (pc) {
			person?.removeFromCharacteristics(pc)
			characteristic?.removeFromPeople(pc)
			pc.delete()
		}
	}
}
</pre>
<p><strong>Note:</strong> if you want an explanation of this class <a href="http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML">look here</a> and read the section <em>The Many-to-Many map</em>.</p>
<p>Now, with any luck we&#8217;ll be able to do this with the console&#8230;</p>
<p>(I would assume you know this but just in case&#8230; go to your project base dir and type&#8230;</p>
<pre>
grails console
</pre>
<p>Now here are some people and characteristics. This is the easy part.</p>
<pre class="brush: java">
def a = new Person(firstName: &quot;Jeff&quot;, lastName: &quot;Revert&quot;)
a.save()
def b = new Person(firstName: &quot;Priyatam&quot;, lastName: &quot;Console&quot;)
b.save()
def c = new Characteristic(name: &quot;Stupid&quot;, description: &quot;slow of mind&quot;)
c.save()
def d = new Characteristic(name: &quot;Handsome&quot;, description: &quot;a pleasing appearance&quot;)
d.save()
</pre>
<p>you should see this output if you&#8217;re following along correctly:</p>
<blockquote><p>
Result: Characteristic : 2
</p></blockquote>
<p>But why take my word for it? Test it!</p>
<pre class="brush: java">
def jeff = Person.findByFirstName(&#039;Jeff&#039;)
def priyatam = Person.findByFirstName(&#039;Priyatam&#039;)
def stupid = Characteristic.findByName(&#039;Stupid&#039;)
def handsome = Characteristic.findByName(&#039;Handsome&#039;)
if(jeff) {
    println &quot;Found Jeff&quot;
}
if(priyatam) {
    println &quot;Found Priyatam&quot;
}
if(stupid) {
    println &quot;Found Stupid&quot;
}
if(handsome) {
    println &quot;Found Handsome&quot;
}
</pre>
<p>You should see this output:</p>
<blockquote><p>
Found Jeff<br />
Found Priyatam<br />
Found Stupid<br />
Found Handsome
</p></blockquote>
<p>Next we need to add our characteristics to our people.</p>
<pre class="brush: java">
def person = Person.findByFirstName(&#039;Jeff&#039;)
def characteristic = Characteristic.findByName(&#039;Stupid&#039;)
person.addCharacteristic(characteristic)
</pre>
<p>and the resulting output:</p>
<blockquote><p>
Result: [Characteristic : 1]
</p></blockquote>
<p>I should be set with my many to many relationship!</p>
<p>Not convinced? I know how you feel&#8230;</p>
<p>One problem with Grails default database config is that you can&#8217;t easily go there and check out the schema. Well, I don&#8217;t know how to anyway, and I&#8217;m guessing I&#8217;m not alone. In my real world job I always check out the database. It&#8217;s like a security blanket, only with a penchant for evil. Anyway, it&#8217;s not that <a href="http://hsqldb.org/">HSQLDB</a> can&#8217;t provide it, it&#8217;s that the config isn&#8217;t running an in-memory database capable of connecting to. So change the development datasource url to this:</p>
<pre>
url = "jdbc:hsqldb:hsql://localhost:9001/devDB"
</pre>
<p>Open a new shell, go to your grails install directory, and run this:</p>
<pre>
java -cp ./lib/hsqldb-1.8.0.5.jar org.hsqldb.Server -database.0 mem:devDB -dbname.0 devDB
</pre>
<p>This will run an in memory database server that you can connect to with your favorite database exploring app. Now fire up the grails console again, and let&#8217;s add this stuff again.<br />
After adding the people and characteristics, and adding the PersonCharacteristic, check out the tables. I see PERSON, CHARACTERISTIC, and PERSON_CHARACTERISTIC.</p>
<pre>
select * from person_characteristic
</pre>
<p>and this shows I&#8217;ve got a PERSON_CHARACTERISTIC table with an ID, VERSION, CHARACTERISTIC_ID, PERSON_ID, and ASSIGNED_VALUE columns with values 1,0,1,1,1. So you get exactly what you&#8217;d expect. Not bad!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/grails-manytomany-gorm-example/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>GORM Relationships in the Grails Console</title>
		<link>http://www.reverttoconsole.com/blog/grails/gorm-relationships-in-the-grails-console/</link>
		<comments>http://www.reverttoconsole.com/blog/grails/gorm-relationships-in-the-grails-console/#comments</comments>
		<pubDate>Fri, 30 May 2008 02:10:03 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/187</guid>
		<description><![CDATA[I&#8217;ve just started scratching the surface with Grails. A good starting point seems to be understanding GORM or Grails Object Relational Mapping, which is based on Hibernate3. In looking at the Grails tutorials online, you might be inclined to start using Grails via scaffolding and generating controllers and views. And this is fine, but another [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just started scratching the surface with Grails. A good starting point seems to be understanding <a href="http://docs.codehaus.org/display/GRAILS/GORM">GORM </a>or Grails Object Relational Mapping, which is based on <a href="http://www.hibernate.org/">Hibernate3</a>.</p>
<p>In looking at the Grails tutorials online, you might be inclined to start using Grails via scaffolding and generating controllers and views. And this is fine, but another perhaps smaller step alternative is to start with the <a href="http://grails.org/doc/1.0.x/ref/Command%20Line/console.html">Grails Console</a> and mess around with the relationships you&#8217;re likely to form in the database.</p>
<p>I found that diving in with some of the tutorials, it isn&#8217;t always obvious why you&#8217;d dynamically scaffold versus performing a static scaffold, or you might not pick up on the power of groovy pages immediately. So I found working with the grails console and GORM to start with eliminated some of the mystery, and provided a solid foundation for further learning. <a href="http://reverttoconsole.com/archives/186">In my previous post</a> I discussed some of the subtle, perhaps unexpected, issues with persisting domain objects in the grails console. Here&#8217;s how I added relationships (after the jump).</p>
<p><span id="more-159"></span></p>
<p>Let&#8217;s start with person and characteristic domain objects:</p>
<pre>
grails create-domain-class person
grails create-domain-class characteristic
</pre>
<p>This will create domain class Person, which we will edit to look like:</p>
<pre class="brush: java">
class Person {
        static hasMany = [characteristics:Characteristic]
	static optionals = [&#039;middleInitial&#039;]
        static constraints = {middleInitial(maxLength:1)}
	String firstName
	String lastName
	String middleInitial
}
</pre>
<p>and the Characteristic class:</p>
<pre class="brush: java">
class Characteristic {

	static belongsTo = Person
	static optionals = [&#039;displayName&#039;]
	String name
	String displayName
	Integer systemLevel
}
</pre>
<p>Now fire up the grails console, you can persist the relationship as follows:</p>
<p>[/java]<br />
def c = new Characteristic(name: &#8220;lazy&#8221;, displayName: &#8220;exudes laziness&#8221;, systemLevel: 1)<br />
def p = new Person(firstName: &#8220;Jeff&#8221;, lastName: &#8220;Smith&#8221;, middleInitial: &#8220;S&#8221;,<br />
characteristics:[c])<br />
p.save()<br />
[/java]</p>
<p>After executing, this should display:</p>
<pre>
Result: Person : 1
</pre>
<p>And how about some built-in querying?</p>
<p>Domain object plus .get(id) will retrieve by identifier:</p>
<pre class="brush: java">
def newGuy = Person.get(1)

if(newGuy) {
println newGuy.firstName
} else {
println &quot;No new guy was found!&quot;
}
</pre>
<p>You should see &#8220;Jeff&#8221; as the output.</p>
<p><a href="http://grails.org/doc/1.0.x/guide/single.html#5.4.1%20Dynamic%20Finders">Dynamic finders</a> are where you really see some interesting things:</p>
<pre class="brush: java">
def f = Person.findByFirstName(&#039;Jeff&#039;)
if(f) {
  println f.lastName
  println f.characteristics.each{ println it.name }
} else {
  println &quot;No Person with the first name of Jeff was found!&quot;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/grails/gorm-relationships-in-the-grails-console/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Grails Startup Pain</title>
		<link>http://www.reverttoconsole.com/blog/groovy/grails-startup-pain/</link>
		<comments>http://www.reverttoconsole.com/blog/groovy/grails-startup-pain/#comments</comments>
		<pubDate>Tue, 27 May 2008 16:06:10 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/186</guid>
		<description><![CDATA[Grails is a composed of a stack I like, a combination of technologies I&#8217;ve enjoyed using over the last few years- Groovy, HSQLDB, Spring, Hibernate, etc. And the whole seems greater than the sum of its parts, so while I&#8217;m complaining about it today, I do so knowing that with future releases Grails could really [...]]]></description>
			<content:encoded><![CDATA[<p>Grails is a composed of a stack I like, a combination of technologies I&#8217;ve enjoyed using over the last few years- Groovy, HSQLDB, Spring, Hibernate, etc. And the whole seems greater than the sum of its parts, so while I&#8217;m complaining about it today, I do so knowing that with future releases Grails could really deliver a great solution.</p>
<p>One thing that many new frameworks are striving to offer these days is a quick startup- you can push this button, pull this lever, and voila, you have a hello world and can build from there. Of course this sounds better than writing a domain class, a dao, a service class, then enter some BS in your web.xml, and wire your beans, and add a *-servlet.xml, configure log4j, etc etc etc. And it is. Except when it doesn&#8217;t work.</p>
<p>My initial attempt at creating a Grails project went like this:</p>
<ul>
<li><em>grails create-app</em> created my application.</li>
<li><em>import project</em> imported my project into Eclipse. I ended up with 25 or so classes in my base directory.</li>
<li><em>grails run-app</em> runs Jetty. I pull up a browser and can see my new site- everything appears to be going great.</li>
<li><em>grails create-domain-class</em> Create a domain class. Edit the domain class file, add a few properties. Easy.</li>
<li><em>grails create-controller</em> Creates a controller class. Remove the index() method and add def scaffold = domain class.</li>
<li><em>grails run-app</em> start my server again. This time I see my controller, click on it.
</ul>
<blockquote><p>NullPointerException</p></blockquote>
<p>The crazy thing is, this is after following directions from <a href="http://www.amazon.com/Definitive-Guide-Grails/dp/1590597583">the book written by the lead developer of the Grails</a> project! Ouch!</p>
<p>Here&#8217;s another example:</p>
<p><a href="http://grails.org/Quick+Start">The getting started with Grails documentation</a> highlights using Bootstrap.groovy in grails-app/conf as a place to inject test data.</p>
<p>So for example, using a domain class Bookmark, in the Bootstrap.groovy file you could write:</p>
<pre class="brush: java">
new Bookmark(property1: &quot;value1&quot;, property2: &quot;value2&quot;).save()
</pre>
<p>and have the bookmark show up in the Grails scaffolding.</p>
<p>With this approach I ended up with a &#8220;NoMethodException&#8221; saying that save() was not a valid method for this domain class.</p>
<p>Nice.</p>
<p>Another approach mentioned using the groovy console to add data. I could create an object, such as the Bookmark, but again I could not save it. This time it seemed like after creating it, it could not find the object in the stack.</p>
<p>I will continue to post about this as I find out the source of my problems.</p>
<p><strong>Update 5/28/08:</strong> After rereading the extensive <a href="http://docs.codehaus.org/display/GRAILS/Eclipse+IDE+Integration">&#8220;how to set up a Grails project in Eclipse&#8221;</a> documentation, it became clear that without disabling the Groovy plugin auto-compilation feature, I wouldn&#8217;t have much success. In fact, after last night&#8217;s effort I&#8217;ve made some nice progress and am beginning to see some similarities between Grails and Seam, at least in terms of work-cycle.</p>
<p>I&#8217;m frustrated though, by the fact that grails shell is not working for me. I believe the issue is that <a href="http://jira.codehaus.org/browse/GRAILS-163">I&#8217;m using cygwin</a>. It may be time to just switch over the linux entirely.</p>
<p><strong>Update: </strong> The &#8220;grails console&#8221; option appears to work.<br />
<img src="http://reverttoconsole.com/wiki/images/6/64/Grailsconsole.jpg" alt="Grails Console" /></p>
<p><strong>Update 5/29/08:</strong> One thing I&#8217;ve noticed is that given a domain object like this:</p>
<pre class="brush: java">
class Person {
	static optionals = [&#039;middleInitial&#039;]
	String firstName
	String lastName
	String middleInitial
}
</pre>
<p>In the grails console, you MUST specify the optional property middleInitial in order to successfully create an object. Unfortunately, there&#8217;s no warning or explanation in the console. It just doesn&#8217;t work without all properties being passed in the constructor.</p>
<p>So this will work:</p>
<pre class="brush: java">
def p = new Person(firstName: &quot;test&quot;, lastName: &quot;test&quot;, middleInitial: &quot;m&quot;)
p.save()
</pre>
<p>But this will not:</p>
<pre class="brush: java">
def p = new Person(firstName: &quot;test&quot;, lastName: &quot;test&quot;)
p.save()
</pre>
<p>And neither will this:</p>
<pre class="brush: java">
def p = new Person()
p.firstName = &quot;test&quot;
p.lastName = &quot;test&quot;
p.save()
</pre>
<p>But this will:</p>
<pre class="brush: java">
def p = new Person()
p.firstName = &quot;test&quot;
p.lastName = &quot;test&quot;
p.middleInitial  = &quot;m&quot;
p.save()
</pre>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F&amp;title=Grails+Startup+Pain" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F&amp;title=Grails+Startup+Pain" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F&amp;title=Grails+Startup+Pain" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F&amp;title=Grails+Startup+Pain" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F&amp;title=Grails+Startup+Pain', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F&amp;title=Grails+Startup+Pain" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgrails-startup-pain%2F&amp;title=Grails+Startup+Pain" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/groovy/grails-startup-pain/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Groovy CLIBuilder In Practice</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 15:44:25 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/130</guid>
		<description><![CDATA[Ok, it doesn&#8217;t get much easier than this to build a CLI: class ContentUpdaterMain { static void main(args) { def cli = new CliBuilder(usage: &#039;java -jar contentupdater.jar -su[dh] &#34;update name&#34;&#039;) cli.h(longOpt: &#039;help&#039;, &#039;usage information&#039;) cli.u(longOpt: &#039;update&#039;, &#039;update the provided table&#039;, args: 1) cli.s(longOpt: &#039;stage&#039;, &#039;stage the provided table&#039;, args: 1) cli.d(longOpt: &#039;debug&#039;, &#039;run the process [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, it doesn&#8217;t get much easier than this to build a CLI:</p>
<pre class="brush: java">
class ContentUpdaterMain {

static void main(args) {

def cli = new CliBuilder(usage: &#039;java -jar contentupdater.jar -su[dh] &quot;update name&quot;&#039;)
cli.h(longOpt: &#039;help&#039;, &#039;usage information&#039;)
cli.u(longOpt: &#039;update&#039;, &#039;update the provided table&#039;, args: 1)
cli.s(longOpt: &#039;stage&#039;, &#039;stage the provided table&#039;, args: 1)
cli.d(longOpt: &#039;debug&#039;, &#039;run the process with debugging enabled&#039;)
def opt = cli.parse(args)
if(!opt) return

if(opt.h) cli.usage()

if( opt.d ) {
//turn on debug
}

if(opt.u) {
//do updates
}

if( opt.s ) {
// run against staging db
}
}
}
</pre>
<p>This produces the following usage output:</p>
<pre>usage: java -jar contentupdater.jar -su[dh] "update name"
-d,--debug run the process with debugging enabled
-h,--help usage information
-s,--stage stage the provided table
-u,--update update the provided table</pre>
<p>And all that remains is to validate the input and invoke the processes!</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Groovy Build Script Using AntBuilder Example</title>
		<link>http://www.reverttoconsole.com/blog/groovy/groovy-build-script-using-antbuilder-example/</link>
		<comments>http://www.reverttoconsole.com/blog/groovy/groovy-build-script-using-antbuilder-example/#comments</comments>
		<pubDate>Thu, 26 Jul 2007 19:46:51 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/128</guid>
		<description><![CDATA[As with most things in the life of a Java developer, doing simple things are simple, more complex things though are often much more complicated. For self-described slow learners such as myself, complex tasks become exponentially slower. So it has been with my adoption of the Groovy programming language. Even with the book, it&#8217;s still [...]]]></description>
			<content:encoded><![CDATA[<p>As with most things in the life of a Java developer, doing simple things are simple, more complex things though are often much more complicated. For self-described slow learners such as myself, complex tasks become exponentially slower. So it has been with my adoption of the Groovy programming language. Even with <a href="http://www.manning.com/koenig/"><em>the book</em></a>, it&#8217;s still hard to find examples or adequate documentation for performing tasks <em>the groovy way</em>.</p>
<p>I have written a set of scripts to perform a data migration, but stalled when I went to write a groovy build script. Here&#8217;s what I ended up with:</p>
<pre class="brush: java">
import org.apache.log4j.Logger
import org.apache.tools.ant.listener.Log4jListener
import org.apache.tools.ant.Project

class build {

def ant = new AntBuilder()
static def SRC_DIR 		 = &quot;Source/groovy&quot;
static def DIST_DIR 	         = &quot;dist&quot;
static def CLASSES_DIR        = &quot;bin&quot;
static def LIB_DIR		  = &quot;Source/lib&quot;

def classpath = ant.path {
fileset(dir: &quot;${LIB_DIR}&quot;){
include(name: &quot;*.jar&quot;)
}
pathelement(path: &quot;${CLASSES_DIR}&quot;)
}

def groovyclasspath = ant.path {
fileset( file: &quot;${LIB_DIR}/groovy-all-1.0.jar&quot;)
}

static void main(args) {
def build = new build()
build.run(args)
}

def all() {
ant.mkdir(dir: &quot;${CLASSES_DIR}&quot;)
ant.javac(
destdir: &quot;${CLASSES_DIR}&quot;,
srcdir: &quot;${SRC_DIR}&quot;,
classpath: &quot;${classpath}&quot;)
ant.groovyc(
destdir: &quot;${CLASSES_DIR}&quot;,
srcdir: &quot;${SRC_DIR}&quot;,
includes: &quot;*.groovy&quot;,
classpathref: &quot;${LIB_DIR}&quot;)
}

def void run(args) {
ant.getProject().addBuildListener(new Log4jListener())
ant.taskdef(
name: &quot;groovyc&quot;,
classname: &quot;org.codehaus.groovy.ant.Groovyc&quot;)
if ( args.size() &amp;gt; 0 ) {
invokeMethod(args[0], null )
} else {
all()
}

}
</pre>
<p>The problem with this is that the basic ant logging is gone. This is all I see when I run it with no arguments:</p>
<blockquote><p> 14:19:52,713 [INFO ]**(Log4jListener.java109) Task &#8220;groovyc&#8221; started.<br />
14:19:52,729 [DEBUG]**(Log4jListener.java155) build.groovy omitted as build.class is up to date.<br />
14:19:52,729 [INFO ]**(Log4jListener.java121) Task &#8220;groovyc&#8221; finished.</p></blockquote>
<p>And, as many of you know, ant&#8217;s logging is one of the most important, if not only, way of troubleshooting ant script problems.</p>
<p>Here&#8217;s another attempt, but you can see I&#8217;m just using <strong>echo</strong> here:</p>
<pre class="brush: java">
def ant =new AntBuilder()

def srcDir          =&quot;Source/groovy&quot;
def libDir          =&quot;Source/lib&quot;
def classesDir      =&quot;bin&quot;

ant.sequential{
echo&quot;Creating the output directories&quot;
mkdir(dir:new File(classesDir))

echo&quot;Defining the classpath&quot;
path(id:&quot;path&quot;){
fileset(dir: libDir){
include(name:&quot;**/*.jar&quot;)
}
pathelement(location: classesDir)
}

echo&quot;Defining groovyc task&quot;
taskdef(name:&quot;groovyc&quot;, classname:&quot;org.codehaus.groovy.ant.Groovyc&quot;, classpathref:&quot;path&quot;)

echo&quot;Compiling main classes&quot;
groovyc(srcdir: srcDir, destdir: classesDir, classpathref:&quot;path&quot;)

}
</pre>
<p>I know that with ant in the background, log4j logging must be there somewhere. I did some previous work using the ant api and was able to get basic logging going without too much trouble. This would be so much more useful if that were working.</p>
<p>Interesting groovy build script articles online:</p>
<ul>
<li>This site&#8217;s <a href="http://www.agilejava.org/space/?108/action_viewspace_itemid_126.html">groovy build script</a> example</li>
<li><a href="http://www.javaworld.com/cgi-bin/mailto/x_java.cgi">Java World article</a></li>
<li><a href="http://www.ibm.com/developerworks/library/j-pg12144.html">IBM Article</a></li>
</ul>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F&amp;title=Groovy+Build+Script+Using+AntBuilder+Example" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F&amp;title=Groovy+Build+Script+Using+AntBuilder+Example" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F&amp;title=Groovy+Build+Script+Using+AntBuilder+Example" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F&amp;title=Groovy+Build+Script+Using+AntBuilder+Example" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F&amp;title=Groovy+Build+Script+Using+AntBuilder+Example', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F&amp;title=Groovy+Build+Script+Using+AntBuilder+Example" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fgroovy%2Fgroovy-build-script-using-antbuilder-example%2F&amp;title=Groovy+Build+Script+Using+AntBuilder+Example" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/groovy/groovy-build-script-using-antbuilder-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
