org.eclipse.ui.jarpackager パッケージは、ファイルを Jar ファイルにプログラマチックにエクスポートするためのユーティリティー・クラスを提供します。 以下は、JarPackageData クラスの使用について説明するコードの断片です。
void createJar(IType mainType, IFile[] filestoExport) {
Shell parentShell= ...;
JarPackageData description= new JarPackageData();
IPath location= new Path("C:/tmp/myjar.jar");
description.setJarLocation(location);
description.setSaveManifest(true);
description.setManifestMainClass(mainType);
description.setElements(filestoExport);
IJarExportRunnable runnable= description.createJarExportRunnable(parentShell);
try {
new ProgressMonitorDialog(parentShell).run(true,true, runnable);
} catch (InvocationTargetException e) {
// An error has occurred while executing the operation
} catch (InterruptedException e) {
// operation has been canceled.
}
}
JarPackageData のプラグイン特定サブクラスを作成するために、追加の API が提供されています。 これを使用すると、その他のプラグインで、独自の Jar エクスポート/インポート・ウィザードを実装したり、 JarPackageData オブジェクトの内容を対応する Jar 記述ファイルに保管できます。
JAR が JarPackageData によって記述されると、Jar は JarWriter2 を使用してプログラマチックに作成できます。