How to Create a Windows Installer for an SWT Application : Page 2
Native Windows installers offer unparalleled integration with the operating system, as well as familiar installation for users. Learn how to build a native Windows installer for an SWT application using open source tools.
by Stephen Strenn
Jan 17, 2006
Page 2 of 3
Step 1: Organize Your Libraries
The proper placement and referencing of libraries is critical for Java SWT applications. My sample application, SimpleText, depends on the SWT Win32 JAR, org.eclipse.swt.win32.win32.x86_3.1.0.jar, as well as the SWT Win32 DLL, swt-win32-3138.dll. Note that in newer versions of Eclipse, the DLL is actually archived in the SWT Win32 JAR. The following steps prepare the JAR and DLL for export and installation:
Create a /lib directory under the project root directory.
Place a copy of org.eclipse.swt.win32.win32.x86_3.1.0.jar in the /lib directory.
To let Eclipse know about the JAR, open the project's properties, then select Java Build Path | Add JARs..., and browse for the .jar file in the project's /lib directory (see Figure 2).
Extract the Windows-specific DLL from the SWT Win32 JAR, using the following command-line:
jar xf org.eclipse.swt.win32.win32.x86_3.1.0.jar swt-win32-3138.dll
Place swt-win32-3138.dll in the root of the project directory. Note that while it is possible to load the DLL at runtime and thereby avoid extracting it from the JAR, that approach is not covered here. Also note that you do not need to worry about extracting the other DLL's from the SWT Win32 JAR.
Step 2: Create a Manifest
The JAR manifest, MANIFEST.MF, identifies the application's main class as well as the JARs upon which the application depends:
In Eclipse, create a text file called MANIFEST.MF, for the project.
Add the manifest version, main class, and classpath to it as shown below:
An executable JAR contains your Java .class files, the manifest, and resources (such as images) that your application needs. To create one in Eclipse, follow these steps:
Right-click on the project and select Export... | JAR file.
In the JAR Package Specification, check only the source directories and individual resource files your application needs. For example, SimpleText uses an image resource file, SimpleText16x16.gif, for its SWT shell icon, so that GIF is included in the JAR (see Figure 3).
Set the JAR file field to the desired path and filename. The path should be the same as the path for the SWT Win32 DLL. This is important because the executable JAR's directory is our application startup directory, and the application startup directory is one of the places that Windows will automatically search when looking for DLLs.
Click Next and then Next again to get to the JAR Manifest Selection page. Select "Use existing manifest from workspace," and browse to the MANIFEST.MF file created in Step 2.
Click Finish to have Eclipse create the JAR.
In Windows Explorer, double-click the JAR to verify that the program runs as expected.