Griffon – Faster Groovy Desktop Development

I needed an installable desktop application based on existing Java logic, where the technology should fit in our portfolio. We are mainly based around Java enterprise and web development. Working with Grails I thought it would be a great idea to use Groovy also for the desktop application. With this search I found Griffon, which Fabian also evaluated at the beginning of the year.

After working on the last two evenings with this framework I’m really amazed. Without any real experience with Swing my app is running, packaged for Windows as .exe, for Mac as .dmg. It is the same speed effect you have when working with Rails or Grails for web applications – but now for the desktop. In combination with IntelliJ IDEA and its Jetgroovy plugin it really makes fun. And that’s what it’s all about.

Don’t believe it? Let’s create your installable desktop application in 10min. Description for Mac user (but similar on Windows).

1. Download Griffon

Go to the Griffon download page and download e.g. version 0.9 as binary zip.

2. Extract Griffon

Extract Griffon e.g. to /Library/DevLibs/griffon-0.9 (our location for frameworks like Maven, Grails, …)

3. Configure environment and path

I’m managing my environment in .bash_profile where I need to add the following lines:

export GRIFFON_HOME=/Library/DevLibs/griffon-0.9
export PATH=$GRIFFON_HOME/bin:$PATH

And now you can open the Terminal.

4. Create app

Go to our project directory and type:

griffon create-app

You will be prompted to enter your application name:

Welcome to Griffon 0.9 - http://griffon.codehaus.org/
Licensed under Apache Standard License 2.0
Griffon home is set to: /Library/DevLibs/griffon-0.9
 
Base Directory: /Users/simon/Projekte
Resolving dependencies...
Dependencies resolved in 1320ms.
Running script /Library/DevLibs/griffon-0.9/scripts/CreateApp_.groovy
Environment set to development
Application name not specified. Please enter:
viaboxx

5. App layout

If you are familiar with Grails, it is nothing new to you:

griffon-app

  • conf: Configuration scripts (yeah, scriptable configuration)
  • controllers: Your controller classes which are tightly coupled with the view classes
  • i18n: Your properties-files (in UTF-8 like in Grails – unlike Java)
  • lifecycle: Some scripts classes to hook into the lifecycle
  • models: Your model definitions
  • resources: Images and other stuff
  • views: Your view classes

lib (fix dependencies, better use Ivy and configure dependencies in griffon-app/conf/BuildConfig.groovy)

scripts

src (other sources)

6. Modify app

To modify your newly created application go to griffon-app/views/viaboxx/ViaboxxView.groovy

  1. package viaboxx
  2.  
  3. application(title: 'viaboxx',
  4. pack: true,
  5. locationByPlatform:true,
  6. iconImage: imageIcon('/griffon-icon-48x48.png').image,
  7. iconImages: [imageIcon('/griffon-icon-48x48.png').image,
  8. imageIcon('/griffon-icon-32x32.png').image,
  9. imageIcon('/griffon-icon-16x16.png').image]) {
  10. panel() {
  11. borderLayout()
  12.  
  13. hbox(constraints:NORTH) {
  14. textField(id: "nameInput",
  15. columns: 10,
  16. actionPerformed: {controller.textEntered()})
  17. button(text: "Entered",
  18. actionPerformed: {controller.textEntered()})
  19.  
  20. }
  21. label(constraints:SOUTH,
  22. id: "outputLabel",
  23. text: "Enter name above")
  24. }
  25. }

And the matching controller: griffon-app/controllers/viaboxx/ViaboxxController

  1. package viaboxx
  2.  
  3. class ViaboxxController {
  4. // these will be injected by Griffon
  5. def model
  6. def view
  7.  
  8. def textEntered = {
  9. view.outputLabel.text = "Hello World, ${view.nameInput.text}"
  10. }
  11. }

7. Run app

griffon run-app

Easy, isn’t it. And the groovy builder syntax is so short and sexy.

8. Package app

You need to install a plugin (there are a lot of great plugins available)

griffon install-plugin installer
griffon package mac

Find the result in the folder dist. There are a lot of other package modes available. Including ZIP, RPM, EXE, …

9. More Infos

Official page: http://griffon.codehaus.org/

Documentation: http://dist.codehaus.org/griffon/guide/index.html

Installer plugin: http://docs.codehaus.org/display/GRIFFON/Installer+Plugin

Quick Start: http://griffon.codehaus.org/Quick+Start

Sample apps: http://mikusa.blogspot.com/2009/04/griffon-applications.html

10. Is this cool?

If it works, leave a comment and spread the word about Griffon.

Kommentare sind deaktiviert