前提
- JSmoothがインストールされている
手順
以下のbuild.gradleを用意する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'groovy' | |
apply plugin: 'eclipse' | |
archivesBaseName = 'myapp' | |
ext.jsmoothHome = 'C:/program Files/JSmooth 0.9.9-7' | |
configurations { jsmooth } | |
repositories{ | |
flatDir dirs: "${jsmoothHome}/lib" | |
} | |
dependencies{ | |
groovy localGroovy() | |
jsmooth 'net.charabia:jsmoothgen-ant:@jar' | |
} | |
jar { | |
copy { | |
from configurations.runtime | |
into "lib" | |
} | |
def manifestClasspath = configurations.compile.collect{ 'lib/' + it.getName() }.join(' ') | |
manifest { | |
attributes "Main-Class" : "com.example.Main" | |
attributes 'Class-Path': manifestClasspath | |
} | |
from (configurations.compile.resolve().collect { it.isDirectory() ? it : fileTree(it) }) { | |
exclude 'META-INF/MANIFEST.MF' | |
exclude 'META-INF/*.SF' | |
exclude 'META-INF/*.DSA' | |
exclude 'META-INF/*.RSA' | |
exclude '**/*.jar' | |
} | |
} | |
build << { | |
ant.copy(file: 'build/libs/myapp.jar', todir: '.') | |
} | |
task jsmooth << { | |
def basedir = '.' | |
ant.taskdef(name:'jsmoothgen' | |
,classpath:configurations.jsmooth.asPath | |
, classname:"net.charabia.jsmoothgen.ant.JSmoothGen" | |
) | |
ant.jsmoothgen(project:"myapp.jsmooth" | |
,skeletonroot:"${jsmoothHome}/skeletons" | |
) | |
} | |
jsmooth.dependsOn(build) |
6行目に、JSmoothのインストールディレクトリを指定する。JSmoothのAntタスクを呼び出すために、jsmoothという名前のconfigurationを定義し(8行目)、そのconfigurationにJSmoothのantタスクのjarを指定(16行目)する。
jarタスク(19行目)で、依存関係のあるjarをlibフォルダにコピー(20-23行目)した上で、実行可能jarを作成している。実行可能jarの作成については、下記サイトの内容をもとにしている。
jsmoothタスク(42行目)で、JSmoothのAntタスクを呼び出し、実行可能jarをexe化している。Antタスク呼び出すjsmoothの設定ファイルは、あらかじめjsmoothを使って保存しておく必要がある。jsmoothの設定については、下記を参照。
なお、この例で使用したjsmoothの設定ファイルは以下の通り。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<jsmoothproject> | |
<JVMSearchPath>registry</JVMSearchPath> | |
<JVMSearchPath>javahome</JVMSearchPath> | |
<JVMSearchPath>jrepath</JVMSearchPath> | |
<JVMSearchPath>jdkpath</JVMSearchPath> | |
<JVMSearchPath>exepath</JVMSearchPath> | |
<JVMSearchPath>jview</JVMSearchPath> | |
<classPath>lib\groovy-all-1.8.6.jar</classPath> | |
<embeddedJar>true</embeddedJar> | |
<executableName>myapp.exe</executableName> | |
<initialMemoryHeap>-1</initialMemoryHeap> | |
<jarLocation>myapp.jar</jarLocation> | |
<mainClassName>com.example.Main</mainClassName> | |
<maximumMemoryHeap>-1</maximumMemoryHeap> | |
<maximumVersion></maximumVersion> | |
<minimumVersion></minimumVersion> | |
<skeletonName>Console Wrapper</skeletonName> | |
<skeletonProperties> | |
<key>Message</key> | |
<value>This program needs Java to run. | |
Please download it at http://www.java.com</value> | |
</skeletonProperties> | |
<skeletonProperties> | |
<key>PressKey</key> | |
<value>0</value> | |
</skeletonProperties> | |
<skeletonProperties> | |
<key>Debug</key> | |
<value>0</value> | |
</skeletonProperties> | |
</jsmoothproject> |
jsmoothタスクを実行すると、実行可能jarがexe化される。なお、このexeはlibフォルダとともに配布する必要がある点に注意。