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
[codesyntax lang="groovy"] <pre>package viaboxx application(title: 'viaboxx', pack: true, locationByPlatform:true, iconImage: imageIcon('/griffon-icon-48x48.png').image, iconImages: [imageIcon('/griffon-icon-48x48.png').image, imageIcon('/griffon-icon-32x32.png').image, imageIcon('/griffon-icon-16x16.png').image]) { panel() { borderLayout() hbox(constraints:NORTH) { textField(id: "nameInput", columns: 10, actionPerformed: {controller.textEntered()}) button(text: "Entered", actionPerformed: {controller.textEntered()}) } label(constraints:SOUTH, id: "outputLabel", text: "Enter name above") } }</pre> [/codesyntax]
And the matching controller: griffon-app/controllers/viaboxx/ViaboxxController
[codesyntax lang="groovy"] <pre>package viaboxx class ViaboxxController { // these will be injected by Griffon def model def view def textEntered = { view.outputLabel.text = "Hello World, ${view.nameInput.text}" } }</pre> [/codesyntax]
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