Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




EclipseJDT Plug-in Developer Guide
Previous Page Home Next Page

Programmatically Writing a Jar file

The org.eclipse.ui.jarpackager package provides utility classes to programmatically export files to a Jar file. Below is a code snippet that outlines the use of the JarPackageData class:

    void createJar(IType mainType, IFile[] filestoExport) {
        Shell parentShell= ...;
        JarPackageData description= new JarPackageData();
        IPath location= new Path("C:/tmp/myjar.jar");
        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.

Additional API is provided to create a plug-in specific subclass of JarPackageData. This allows other plug-ins to implement their own Jar export/import wizards and to save the content of the JarPackageData object to a corresponding Jar description file.

Once the JAR is described by a JarPackageData, it can be programmatically written using a JarWriter3.

  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire