## SWT standalone examples setup

### Importing example source

*** In the following description, substitute the location in which you installed Eclipse for INSTALLDIR ***

Import the example code and all its required resources into your workspace:

1. Create a Java Project called "SWT Examples".
2. Select the project "SWT Examples" in the Packages view.
3. Select the File > Import menu, then select Zip File from the subsequent dialog and click Next.
4. Locate the source zip file for the SWT examples. For example:
   - win32: `INSTALLDIR\eclipse\plugins\org.eclipse.sdk.examples.source_3.0.0\src\org.eclipse.swt.examples_3.0.0\swtexamplessrc.zip`
   - *ix: `INSTALLDIR/eclipse/plugins/org.eclipse.sdk.examples.source_3.0.0/src/org.eclipse.swt.examples_3.0.0/swtexamplessrc.zip`
5. Click Finish.
6. Select the File > Import menu, then select Zip File from the subsequent dialog and click Next.
7. Locate the jar file for the SWT examples. For example:
   - win32: `INSTALLDIR\eclipse\plugins\org.eclipse.swt.examples_3.0.0\swtexamples.jar`
   - *ix: `INSTALLDIR/eclipse/plugins/org.eclipse.swt.examples_3.0.0/swtexamples.jar`
8. Expand the top level directory of the jar file (/), uncheck "META-INF", and click Finish.
9. In the resulting "Overwrite?" prompter click No To All so that only non-class resources will be imported.

Now you need to compile the SWT examples. In order to do this, you must add the SWT jar(s) to the compile path:

1. Select the project "SWT Examples" in the Packages view, and from its context menu select Properties.
2. Select the Java Build Path page, and then select its Libraries tab.
3. Click on the Add External JARs... button.
4. Locate the swt jar for the platform on which you wish to run:
   - win32: `INSTALLDIR\eclipse\plugins\org.eclipse.swt.win32_3.0.0\ws\win32\swt.jar`
   - gtk: `INSTALLDIR/eclipse/plugins/org.eclipse.swt.gtk_3.0.0/ws/gtk/swt.jar`
   - motif: `INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_3.0.0/ws/motif/swt.jar`
   - photon: `INSTALLDIR/eclipse/plugins/org.eclipse.swt.photon_3.0.0/ws/photon/swt.jar`
   - macosx: `INSTALLDIR/eclipse/plugins/org.eclipse.swt.carbon_3.0.0/ws/carbon/swt.jar`
5. Click on OK.

NOTE: For some platforms, such as GTK, more than one jar is required to run SWT (on GTK there is a swt.jar and a swt-pi.jar and a swt-mozilla.jar file). In this case all of the required jars must be added to the class path. This is done by repeating the steps above for each jar file. All jar files are located in the same directory/folder.

At this point your SWT examples should be compiled without any errors. Check the Tasks view for errors. If you get an error like "`java.lang.Object` not found" it means you have not configured a JRE. Go to the Window > Preferences dialog and select the Java > Installed JREs preference page and ensure that a JRE is installed and that the path to the JRE is correct.

### Running the Example

Now you have to configure Eclipse to run the example. This requires putting the SWT JNI libraries on the library path so that the VM can find them:

1. Open the Java perspective.
2. In the Packages view, select the main class that you want to run. For example, the main class for the Address Book example is `org.eclipse.swt.examples.addressbook.AddressBook`.
3. Select Run > Run... from the main menu.
4. In the Launch Configurations dialog that appears, select Java Application and click on the New button.
5. Fill in the Name, Project and Main class fields according to the example that you wish to run.
6. Select the Arguments tab. In the VM Arguments area specify the location of the SWT library depending on your target platform as follows:
   - win32: `-Djava.library.path=INSTALLDIR\plugins\org.eclipse.swt.win32_3.0.0\os\win32\x86`
   - linux gtk: `-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.gtk_3.0.0/os/linux/x86`
   - linux motif: `-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_3.0.0/os/linux/x86`
   - solaris motif: `-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_3.0.0/os/solaris/sparc`
   - aix motif: `-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_3.0.0/os/aix/ppc`
   - hpux motif: `-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_3.0.0/os/hpux/PA_RISC`
   - photon qnx: `-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.photon_3.0.0/os/qnx/x86`
   - macosx: `-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.carbon_3.0.0/os/macosx/ppc`
7. Click on the Run button.

### Examples Overview

Consult the documentation of each individual example for the name of its main class and additional details. The following examples are included in the `swtexamples.jar`:

- Address Book
- Clipboard
- Controls
- Custom Controls
- File Viewer
- Hello World [1-5]
- Hover Help
- Image Analyzer
- Java Syntax Viewer
- Layouts
- Text Editor