id:fumokmmさんのところで紹介されていたGroovyスクリプトを実行可能jarにまとめられるというスクリプトが紹介されていた。
No Programming, No Life
セットアップ方法は非常に簡単。使用してみると確かにスクリプトとGroovyの実行に必要なjarが実行可能jarにひとまとめになった。
生成された実行可能jarはダブルクリックするなりコマンドラインから
にて実行できるので、Groovyがインストールされていない環境でも実行できる。これが何より大きい。
動作時の僕の環境は以下のとおり。
1
2
| $ groovy -version
Groovy Version: 1.7.2 JVM: 1.6.0_20
|
Swingもいけるのか?
Swingアプリもいけるかと思って試してみた。
こちら(Groovy - Swing Builder)のSwingBuilderサンプルコードを拝借。
hello.Groovy
1
2
3
4
5
6
7
8
9
10
11
12
| import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
count = 0
new SwingBuilder().edt {
frame(title:'Frame', size:[300,300], show: true) {
borderLayout()
textlabel = label(text:"Click the button!", constraints: BL.NORTH)
button(text:'Click Me',
actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"},
constraints:BL.SOUTH)
}
}
|
上記hello.groovyを/tmpフォルダに作成。
ほいで実行可能jarを作成。
1
2
| cd /tmp
groovy GroovyWrapper.groovy -c -m hello
|
実行。
Swingアプリも問題なく起動を確認。ちょっとしたスクリプトを開発メンバーに公開するときに重宝しそうだ。