Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

How to Create a Windows Installer for an SWT Application : Page 3

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.


advertisement

Step 4: Create Icons and Images

Now we need to create two icons (.ico) and a bitmap (.bmp). One icon is for display in the Windows Start Menu and one is for the installer application itself. The bitmap will be used to display a logo during installation:
  1. Create an /images subdirectory under the project root.
  2. Create an icon for the program and put it in the /images directory. Windows .ico files can contain multiple icons of different sizes (16x16, 32x32, and 48x48 are typical). If you do not have a tool that creates Windows .ico files directly, you can create .png files first, then merge them into an .ico file with png2ico.
  3. Create an /installer subdirectory under the project.
  4. Create a small (say 150x70) .bmp image for the application logo, and put it in the /installer directory.
  5. Create or find a 16x16 .ico file for the installer executable and put it in the /installer directory. setup.ico, which is included with the downloadable samples for this article, is a standard Windows setup icon.

Step 5: Create an NSIS Installer Script

NSIS is an open-source tool for the development of professional-grade Windows installers. It sports standard features such as install, shortcut creation, and uninstall, as well as many advanced features such as custom dialogs, system reboots, and DLL/ActiveX control registration. A complete discussion of NSIS usage is beyond the scope of this article, so I will simply focus on what changes would need to be made to SimpleTextInstaller.nsi (see Listing 2) to get it to work for your own application:
  1. Download and install NSIS.
  2. Copy SimpleTextInstaller.nsi, the NSIS script, into the /installer directory.
  3. Search for SimpleText and replace it with the name of your application.

    Click to enlarge 
    Figure 4. SimpleText: Up and Running



  4. Search for Cogito Research and replace it with the name of your organization or company.
  5. Search for C:\temp\SimpleText\installer and replace it with the path to your /installer directory.
  6. Modify /installer/License.txt as appropriate for your application.
  7. Under ;Files to be installed, list all files that are to be transferred to the end user's computer. For SimpleText, the ;Files to be installed are:

    SetOutPath "$INSTDIR" File "C:\temp\SimpleText\SimpleText_1.0.jar" File "C:\temp\SimpleText\images\SimpleText.ico" File "C:\temp\SimpleText\swt-win32-3138.dll" SetOutPath "$INSTDIR\lib" File "C:\temp\SimpleText\lib\org.eclipse.swt.win32.win32.x86_3.1.0.jar" SetOutPath "$INSTDIR"

    Note that $INSTDIR equates to the end user's \Program Files\CompanyName\ApplicationName directory and that the script uses the SetOutPath instruction to deploy files to different subdirectories.
  8. Have a look at the section in Listing 2 labeled "Start Menu Shortcuts." It contains entries to create a SimpleText folder in the Windows Start Menu (under All Programs). The last line in the section,

    CreateShortCut "$SMPROGRAMS\SimpleText\SimpleText.lnk" "$INSTDIR\SimpleText_1.0.jar" "" "$INSTDIR\SimpleText.ico"

    is the instruction that creates the start menu launcher for the application. It assumes that the required JRE is already installed on the system.
  9. In the Windows Explorer, right-click on your .nsi script, and select Compile NSIS Script. Assuming that there are no NSIS compile errors, this action should place a Windows installer in your /installer directory.
  10. Be sure to test the installer on both the development machine and at least one end user machine. When installed and running, SimpleText appears as shown in Figure 4.


Stephen Strenn obtained his Master's Degree in Electrical Engineering from the University of California at Davis. He is a principal investigator at the Cogito Research Group and a consultant for the infrared detector industry. He has previously published in the areas of evolutionary computation, artificial intelligence, and robotics.
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap