使用程序编写 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.
    }
}


提供了附加 API 来创建 JarPackageData 的特定于插件的子类。这允许其它插件实现它们自己的 Jar 导出/导入向导,并将 JarPackageData 对象的内容保存到相应的 Jar 描述文件中。

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