*** 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:
INSTALLDIR\eclipse\plugins\org.eclipse.swt.examples_2.1.0\swtexamplessrc.zip
INSTALLDIR/eclipse/plugins/org.eclipse.swt.examples_2.1.0/swtexamplessrc.zip
INSTALLDIR\eclipse\plugins\org.eclipse.swt.examples_2.1.0\swtexamples.jar
INSTALLDIR/eclipse/plugins/org.eclipse.swt.examples_2.1.0/swtexamples.jar
Now you need to compile the SWT examples. In order to do this, you must add the SWT jar(s) to the compile path:
INSTALLDIR\eclipse\plugins\org.eclipse.swt.win32_2.1.0\ws\win32\swt.jar
INSTALLDIR/eclipse/plugins/org.eclipse.swt.gtk_2.1.0/ws/gtk/swt.jar
INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.0/ws/motif/swt.jar
INSTALLDIR/eclipse/plugins/org.eclipse.swt.photon_2.1.0/ws/photon/swt.jar
INSTALLDIR/eclipse/plugins/org.eclipse.swt.carbon_2.1.0/ws/carbon/swt.jar
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 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.
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:
org.eclipse.swt.examples.addressbook.AddressBook
.
-Djava.library.path=INSTALLDIR\plugins\org.eclipse.swt.win32_2.1.0\os\win32\x86
-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.gtk_2.1.0/os/linux/x86
-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.0/os/linux/x86
-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.0/os/solaris/sparc
-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.0/os/aix/ppc
-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.0/os/hpux/PA_RISC
-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.photon_2.1.0/os/qnx/x86
-Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse.swt.carbon_2.1.0/os/macosx/ppc
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
: