SWT アプリを jar にまとめて,ダブルクリックで実行するよ。
どうもですっ!
せっかく SWT でアプリ作っても,ダブルクリックで実行できないと,
げんなりするよね。ダブルクリックばんざい。
結論
参考ページを参考にすればいける。
ざっくりとした説明
- プロジェクトのトップディレクトリを,仮に prj とする。
- で,こんな感じになっているとする。
% pwd /hoem/whitypig/project/prj % ls build.xml classes docs lib src % ls lib org.eclipse.core.commands_3.5.0.I20090525-2000.jar org.eclipse.core.runtime_3.5.0.v20090525.jar org.eclipse.equinox.common_3.5.0.v20090520-1800.jar org.eclipse.jface.databinding_1.3.0.I20090525-2000.jar org.eclipse.jface.text_3.5.0.v20090602.jar org.eclipse.jface_3.5.0.I20090525-2000.jar org.eclipse.swt.win32.win32.x86_3.5.0.v3550b.jar
- jar ファイルを展開する。
% jar xf ./lib/org.eclipse.swt.win32.win32.x86_3.5.0.v3550b.jar
- DLL ファイルをプロジェクトのトップディレクトリにコピー。
% cp ./lib/*.dll ./
build.xml に手を入れる。
まず,試してみようと思い,org 以下のクラスを全部入れてみたところ,
動いたので,いけるかなぁという感じ。jface とかだとちと違うかもしれん。
以下,build.xml から一部を引用。
<property name="classes" location="classes"/> <!-- jar の名前を指定できる。 --> <property name="pkg" location="sample.jar"/> ... <target name="build" depends="compile" description="Generate the distribution"> <jar jarfile="${pkg}"> <!-- この辺をいじくる --> <fileset dir="${classes}" includes="**/*.class"/> <fileset dir="lib" includes="org/**/*.class"/> <fileset dir="." includes="*.dll"/> <!-- 実行したいクラスを指定する。ここでは,Main クラスとする。 --> <manifest> <attribute name="Main-Class" value="Main"/> </manifest> </jar> </target>
あとは Ant におまかせ。
% ant build ... BUILD SUCCESSFUL Total time: 2 seconds
これでできあがったはず。
% start sample.jar
すると,実行できるはず。ダブルクリックでもいいけど。
(ちなみに,ワタシは,start を,cygstart へのシンボリックリンクにしています。)
補足
カレントディレクトリとその下は,次の様になっています。
(ls **/* するとえらいことになるので,ls * ね。)
% ls * build.xml sample.jar swt-awt-win32-3550.dll swt-gdip-win32-3550.dll swt-wgl-win32-3550.dll swt-win32-3550.dll swt-xulrunner-win32-3550.dll classes: Main.class docs: lib: META-INF about.html about_files external.xpt fragment.properties org ## <-- この下にいっぱいクラスファイルが入っていて,それも一緒にjarします。 org.eclipse.core.commands_3.5.0.I20090525-2000.jar org.eclipse.core.runtime_3.5.0.v20090525.jar org.eclipse.equinox.common_3.5.0.v20090520-1800.jar org.eclipse.jface.databinding_1.3.0.I20090525-2000.jar org.eclipse.jface.text_3.5.0.v20090602.jar org.eclipse.jface_3.5.0.I20090525-2000.jar org.eclipse.swt.win32.win32.x86_3.5.0.v3550b.jar swt-awt-win32-3550.dll swt-gdip-win32-3550.dll swt-wgl-win32-3550.dll swt-win32-3550.dll swt-xulrunner-win32-3550.dll version.txt src: Main.class
まとめ
実際の構造とか名前を説明用に変更しているので,間違いがあるかもです。
また,build.xml は,jde に作ってもらいました。(M-x jde-gen-ant-buildfile)
それから,できあがった jar を配布する場合は,
ライセンスに気をつけた方がいいと思います。よく知らんけど。
結局 eclipse を使わずに頑張ってるよ!
お疲れっした!
関連書籍
Professional Java Native Interfaces with SWT/JFace (Programmer to Programmer)
posted with amazlet at 09.10.05
Jackwind Li Guojie
Wrox
売り上げランキング: 148584
Wrox
売り上げランキング: 148584
基本,http://www.eclipse.org/swt/snippets/ とか,
API ドキュメント見れば事足りるけど,その前にこの本をざっくり読んだおかげで,
すんなりドキュメントを読めました。
洋書ですが,平易な英語。非常に,平易だと思う。
ただ,誤植が結構ある。雰囲気つかむのにはいいと思う。