全部博文(626)
分类: Java
2013-10-10 10:19:10
版权声明:作者chszs,版权所有,谢绝转载!
一、介绍
Griffon是一个类似于Grails的应用程序框架,用于构建富桌面应用程序,基于Groovy、Java和Swing等技术。
Griffon采用了习惯优于配置,可以自动化实现很多通用开发任务,而且还有丰富的插件。
Griffon还具有将特征属性绑定到Widget和可扩展的事件系统。这些特性使得用Griffon来构建富互联网应用是极好的选择。
Griffon是一个全生命周期框架:它不仅在创建应用程序、维护应用程序阶段可以自动化,而且在构建和部署阶段也是如此。下面,我们将开始创建、运行、打包、部署一个Java WebStart应用程序,让大家快速掌握Griffon的基本知识。
二、先决条件
1. JDK 6
下载并安装JDK 6以上版本。
2. Griffon包
在 下载Griffon 1.0.2发布包。
三、搭建环境
1. 解压Griffon
将griffon-1.0.2-bin.zip解压到C:\griffon
2. 设置环境变量
设置名为GRIFFON_HOME的环境变量,并把值指向解压目录。
为PATH环境变量添加GRIFFON_HOME/bin值。
注意:一定要设置环境变量,否则在命令行下无法执行griffon命令。
3. 验证
通过CMD进入到命令行模式,执行以下命令:
C:\griffon\bin>griffon help
Welcome to Griffon 1.0.2 -
Licensed under Apache Standard License 2.0
Griffon home is set to: C:\griffon
......
注意:首次运行会自动下载安装或升级一些库或包,如下:
griffon-swing-1.0.1-release.zip,
griffon-jumpstart-1.3-release.zip,
griffon-presentation-1.1-release.zip,
griffon-swt-1.0-release.zip,
ant-1.8.2.jar,
ant-launcher-1.8.2.jar,
ant-junit-1.8.2.jar,
jansi-1.7.jar,
jline-0.9.94.jar,
commons-io-2.1.jar,
commons-lang-2.6.jar,
commons-codec-1.6.jar,
commons-collections-3.2.1.jar,
commons-beanutils-1.8.0.jar,
httpcore-4.1.2.jar,
httpclient-4.1.2.jar,
jsch-0.1.45.jar,
jzlib-1..7.jar,
http-builder-0.5.2.jar,
xercesImpl-2.9.1.jar,
ezmorph-1.0.6.jar,
xml-resolver-1.2.jar,
griffon-cli-1.0.2.jar,
griffon-scripts-1.0.2.jar,
griffon-rt-1.0.2.jar,
org.springframework.core-3.1.2.RELEASE.jar,
org.springframework.beans-3.1.2.RELEASE.jar,
org.springframework.context-3.1.2.RELEASE.jar,
org.springframework.context.suppor-3.1.2.RELEASE.jar,
json-lib-2.4-jdk15.jar,
log4j-1.2.16.jar,
slf4j-api-1.6.4.jar,
slf4j-log4j12-1.6.4.jar,
jcl-over-slf4j-1.6.4.jar,
jul-to-slf4j-1.6.4.jar,
groovy-all-1.8.6.jar
4. griffon常用命令
griffon add-proxy
griffon app
griffon archetype-info
griffon clean
griffon clear-dependency-cache
griffon clear-proxy
griffon compile
griffon console
griffon create-addon
griffon create-app
griffon create-archetype
griffon create-command-alias
griffon create-integration-test
griffon create-mvc
griffon create-plugin
griffon create-script
griffon create-service
griffon create-unit-test
griffon dependency-report
griffon doc
griffon generate-view-script
griffon help
griffon init
griffon install-archetype
griffon install-plugin
griffon integrate-with
griffon interactive
griffon list-archetype-updates
griffon list-archetypes
griffon list-plugin-updates
griffon list-plugins
griffon list-repositories
griffon package
griffon package-archetype
griffon package-plugin
griffon plugin-info
griffon release
griffon release-archetype
griffon release-plugin
griffon remove-proxy
griffon replace-artifact
griffon run-app
griffon run-applet
griffon run-script
griffon run-webstart
griffon set-proxy
griffon set-version
griffon shell
griffon stats
griffon test-app
griffon uninstall-archetype
griffon uninstall-plugin
griffon upgrade
四、开发初步
1. 创建应用程序
创建应用程序使用griffon create-app命令。比如:
D:\tmp>griffon create-app HelloWorld
Welcome to Griffon 1.0.2 -
Licensed under Apache Standard License 2.0
Griffon home is set to: C:\griffon
Base Directory: D:\tmp
Running script C:\griffon\scripts\CreateApp_.groovy
Resolving dependencies...
Dependencies resolved in 538ms.
Environment set to development
Resolving framework plugin dependencies ...
Framework plugin dependencies resolved in 725 ms.
[mkdir] Created dir: D:\tmp\HelloWorld\griffon-app
[mkdir] Created dir: D:\tmp\HelloWorld\griffon-app\conf
......
Created Tests for HelloWorld
Created Griffon Application at D:\tmp/HelloWorld
2. 运行应用程序
用Griffon创建的应用程序是桌面应用程序,用户可以安装、Applet应用程序,因此可以让浏览器运行应用程序,或使用WebStart运行等。
Griffon隐藏了各个平台的不同之处,使得应用程序具有可移植性。
要运行应用程序,总共有三种方式:
(1) 以桌面应用程序方式运行程序
D:\tmp>cd HelloWorld
D:\tmp\HelloWorld>griffon run-app
Welcome to Griffon 1.0.2 -
Licensed under Apache Standard License 2.0
Griffon home is set to: C:\griffon
Base Directory: D:\tmp\HelloWorld
Running script C:\griffon\scripts\RunApp.groovy
Resolving dependencies...
......
Launching application ...
2012-08-19 18:18:51,273 [main] INFO griffon.swing.SwingApplication - Initializing all startup groups: [helloWorld]
弹出一窗口程序,如下:
图1:
关闭此窗口程序,输出:
2012-08-19 18:22:48,436 [AWT-EventQueue-0] INFO griffon.swing.SwingApplication- Shutdown is in process
[delete] Deleting directory D:\tmp\HelloWorld\staging\windows64
[delete] Deleting directory D:\tmp\HelloWorld\staging\windows
可见,第一种方式其背后是通过Swing库实现的。
(2) 以Applet程序方式在浏览器中运行
D:\tmp\HelloWorld>griffon run-applet
Welcome to Griffon 1.0.2 -
Licensed under Apache Standard License 2.0
Griffon home is set to: C:\griffon
......
[copy] Copying 11 files to D:\tmp\HelloWorld\staging
[copy] Copying 19 files to D:\tmp\HelloWorld\dist\applet
[copy] Copied 5 empty directories to 4 empty directories under D:\tmp\Hello
World\dist\applet
[zip] Building zip: D:\tmp\HelloWorld\dist\applet\helloWorld-0.1-applet.zip
图2:
由于我安装的是JDK 7,Griffon运行有异常,官方推荐用JDK6。
(3) 以JNLP WebStart项目那样运行
D:\tmp\HelloWorld>griffon run-webstart
Welcome to Griffon 1.0.2 -
Licensed under Apache Standard License 2.0
Griffon home is set to: C:\griffon
......
[copy] Copied 5 empty directories to 4 empty directories under D:\tmp\Hello
World\dist\webstart
[zip] Building zip: D:\tmp\HelloWorld\dist\webstart\helloWorld-0.1-webstart.zip
图3:
同样是JDK7的问题。难怪官方老是推荐要使用JDK6。