How to deploy SWT Applications using Java Web Start

SWT applications can be deployed using Java Web Start (JWS). Here are the steps to help you package and deploy your SWT application with JWS.

First, create jar archives with SWT and its libraries for each platform that you wish to run on:

  1. Create a directory <yourApplication> for collecting the deployable .jar archives.
  2. Go to http://www.eclipse.org/swt and download the desired SWT Release for one of your target platforms. Extract this into a convenient location.
  3. Rename the swt.jar file in the extracted folder to a name that describes its target platform, such as swt-<ws>-<os>-<arch>.jar.
  4. (If you are packaging SWT version 3.3 or newer then this step should be skipped) Create a .jar archive of SWT's native libraries for the target platform by going into the extracted folder and executing "jar cvf swt-native-<ws>-<os>-<arch>.jar *.<library-suffix>". <library-suffix> will be "dll" for Windows and "so" for Linux and Solaris.
  5. Copy the jars from steps 3 and 4 into the <yourApplication> directory. Repeat steps 2 through 4 for each target platform.

Second, create a jar archive with your application:

  1. In Eclipse, select your application's project(s) and invoke the File->Export... menu item.
  2. In the Export wizard selector, select Java - Jar file and press the Next button.
  3. Select the files that are to be deployed, set the export destination to <yourApplication>/<yourApplication>.jar, and press Finish.

Third, sign all jar archives that are to be deployed:

  1. Go into the <yourApplication> folder, execute "keytool -genkey -keystore keystore -alias myself", and enter all required information.
  2. Execute "jarsigner -keystore keystore <yourApplication>.jar myself"
  3. Repeat step 2 for each of the swt-<ws>-<os>-<arch>.jar and swt-native-<ws>-<os>-<arch>.jar archives.

The last step is to create a .jnlp file that will be used to launch your application through JWS (jnlp syntax guide). The example .jnlp file below demonstrates how to specify the SWT jars based on the target platform (note that if you are packaging SWT version 3.3 or newer then the <nativelib> tags are not needed).

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
	codebase="http://www.eclipse.org/swt/jws"
	href="controlexample.jnlp">
	<information>
  		<title>Control Example</title>
  		<vendor>eclipse.org</vendor>
  		<homepage href="http://www.eclipse.org/swt/jws/" />
  		<description>A demonstration of SWT Widgets</description>
  		<description>Control Example</description>
	</information>

	<security>
		<all-permissions />
	</security>

	<resources>
		<j2se version="1.4+" />
		<jar href="controlexample.jar" />
	</resources>

	<resources os="Windows" arch="x86">
		<nativelib href="swt-native-win32-windows-x86.jar" />
		<jar href="swt-win32-windows-x86.jar" />
	</resources>

	<resources os="Windows" arch="x86_64">
		<nativelib href="swt-native-win32-windows-x86_64.jar" />
		<jar href="swt-win32-windows-x86_64.jar" />
	</resources>

	<resources os="Windows" arch="amd64">
		<nativelib href="swt-native-win32-windows-amd64.jar" />
		<jar href="swt-win32-windows-x86_64.jar" />
	</resources>

	<resources os="Linux" arch="ppc">
		<nativelib href="swt-native-gtk-linux-ppc.jar" />
		<jar href="swt-gtk-linux-ppc.jar" />
	</resources>

	<resources os="Linux" arch="x86_64">
		<nativelib href="swt-native-gtk-linux-x86_64.jar" />
		<jar href="swt-gtk-linux-x86_64.jar" />
	</resources>

	<resources os="Linux" arch="amd64">
		<nativelib href="swt-native-gtk-linux-x86_64.jar" />
		<jar href="swt-gtk-linux-x86_64.jar" />
	</resources>

	<resources os="Linux">
		<nativelib href="swt-native-gtk-linux-x86.jar" />
		<jar href="swt-gtk-linux-x86.jar" />
	</resources>

	<resources os="SunOS" arch="sparc">
		<nativelib href="swt-native-gtk-solaris-sparc.jar" />
		<jar href="swt-gtk-solaris-sparc.jar" />
	</resources>

	<resources os="SunOS" arch="x86">
		<nativelib href="swt-native-gtk-solaris-x86.jar" />
		<jar href="swt-gtk-solaris-x86.jar" />
	</resources>

	<application-desc main-class="org.eclipse.swt.examples.controlexample.ControlExample" />
</jnlp>

Now you can test the deployment of your application by pointing your browser at your .jnlp file (note that you must either have Java 1.5 or JWS installed on your machine). You can also create a link to the .jnlp file from an HTML page, as shown below. If all steps have been done correctly then JWS will ask if you want to trust your own unverified signature, and after answering Yes, your application will appear. (Example: http://www.eclipse.org/swt/jws/controlexample.jnlp).

SWT Control Example launched via Java Web Start

Voilà, your application is now deployable via Java Web Start!