Jar ファイルにプログラマチックに書き込む

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 had been canceled.
    }
}


JarPackageData のプラグイン特定サブクラスを作成するために、追加の API が提供されています。 これを使用すると、その他のプラグインで、独自の Jar エクスポート/インポート・ウィザードをインプリメントしたり、JarPackageData オブジェクトの内容を対応する Jar 記述ファイルに保管できます。

Copyright IBM Corporation and others 2000, 2002. All Rights Reserved.