JavaDude's Groovy Snippets and Tutorials

December 24, 2009

Blog moves House

Filed under: Uncategorized — devdude @ 2:33 pm

Due to the restrictive plugin handling at wordpress.com, I move the blog to my own server.
Thanks for the fish !

groovy.bighugesystems.com

December 23, 2009

Create XML file with MarkupBuilder

Filed under: Groovy Snippets — devdude @ 8:45 am
Tags:

The most simple way to create XML content in the standard output or file.

def fw = new FileWriter("/somepath/persons.xml" )
// to write to standard out, remove fw
def xml = new groovy.xml.MarkupBuilder(fw)

xml.content() {

 xml.parameter(x:0)

 xml.person(id:100){
 firstname("John")
 lastname("Long")
 }

 xml.person(id:101){
 firstname("Ken")
 lastname("Smith")
 }
}

Result

<content>
 <parameter x='0' />
 <person id='100'>
 <firstname>John</firstname>
 <lastname>Long</lastname>
 </person>
 <person id='101'>
 <firstname>Ken</firstname>
 <lastname>Smith</lastname>
 </person>
</content>

Please note the difference between MarkupBuilder and StramingMarkupBuilder. More information about XML processing at groovy.codehaus.org
MarkupBuilder is not very flexible, but simple to use for some basic task. If you require comments, XML declarations and more, your rather use the StreamingMarkupBuilder.

December 22, 2009

Groovy 1.7 released

Filed under: Groovy News — devdude @ 6:26 pm
Tags:

Finally released. More information at groovy.codehaus.org

December 16, 2009

Groovy 1.7 and Grails 1.2 soon (Interview)

Filed under: Groovy News — devdude @ 11:00 am

InfoQ: www.infoq.com/interviews/Groovy-1.7-Grails-1.2

December 15, 2009

Groovy: Start from the Scratch

Filed under: General — devdude @ 3:20 pm
Tags: ,

You have nothing but an installed Ubuntu Box, a JDK and no other clue ?

  • Download the latest stable Groovy release from groovy.codehaus.org
  • Unzip the file (maybe to your home folder) and keep the release name, like groovy-1.6.7
  • Modify your .bashrc (gedit ~/.bashrc), usually you need to add this:
    ### GROOVY
    export GROOVY_HOME=/home/whateveryourusername/groovy-1.6.7
    export PATH=$PATH:$GROOVY_HOME/bin
    
  • Open a new shell and type groovy -version and you should get something like this:
    Groovy Version: 1.6.7 JVM: 1.6.0_16
  • Start the console with groovyConsole

    The Groovy Console

  • You are ready, lets get rolling with some snippets.

0.upto(2) { println “$it Hello World” }

Filed under: General — devdude @ 3:05 pm
Tags:

Just started this blog to collect some Groovy Code Snippets, Tutorials, Links and News about Groovy (and Grails and anything nearby). Some stuff might appear ridiculous simple or “Hello Wirld” level, but no one force you to read this.

By the time I get started here Groovy 1.6.7 and Grails are the release versions.

I use Ubuntu 9.10, the GroovyConsole or Netbeans and Eclipse.

Dont ask for completeness, correctness or in-time feedback.

My main blog you find at javadude.wordpress.com

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.