Browse DevX
Sign up for e-mail newsletters from DevX


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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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:

Click to enlarge 
Figure 2. Java Build Path for SimpleText

  1. Create a /lib directory under the project root directory.
  2. Place a copy of org.eclipse.swt.win32.win32.x86_3.1.0.jar in the /lib directory.
  3. 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).
  4. 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

  5. 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:
  1. In Eclipse, create a text file called MANIFEST.MF, for the project.
  2. Add the manifest version, main class, and classpath to it as shown below:

    Manifest-Version: 1.0 Main-Class: com.cogitoresearch.simpletext.MainWindow Class-Path: lib/org.eclipse.swt.win32.win32.x86_3.1.0.jar

Step 3: Create an Executable JAR

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:
  1. Right-click on the project and select Export... | JAR file.
  2. 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).

    Click to enlarge 
    Figure 3. SimpleText's JAR Package Specification

  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.
  4. 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.
  5. Click Finish to have Eclipse create the JAR.
  6. In Windows Explorer, double-click the JAR to verify that the program runs as expected.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date