Das Paket org.eclipse.ui.jarpackager bietet Dienstprogrammklassen zum programmgestützten Exportieren von Dateien in eine JAR-Datei. Nachfolgend ist ein Code-Snippet dargestellt, das die Verwendung der Klasse JarPackageData umreißt:
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.
}
}