Recipe 8.3 Adding the Required SWT JAR Files to the Build Path


Recipe 8.3 Adding the Required SWT JAR Files to the Build Path

8.3.1 Problem

To run an SWT application, Eclipse needs to know where to find the SWT classes.

8.3.2 Solution

Add swt.jar to the build path.

8.3.3 Discussion

To make an SWT application such as the one whose code we created in the previous recipe work, you need to satisfy the imports:

 package org.cookbook.ch08;  import org.eclipse.swt.widgets.*;   import org.eclipse.swt.*;  .         .         . 

All you have to do is to include swt.jar in your build path. As you know, SWT is operating system-dependent, so a different swt.jar will exist for different operating systems.

To add swt.jar to a project, select the project in the Package Explorer, right-click it, and click Properties. In the Properties dialog, click Java Build Path, and click the Add External JARs button. Then navigate to swt.jar , which you'll find in one of the following directories, depending on your operating system ( HOMEDIR is the directory in which you installed Eclipse):



Linux GTK


Linux Motif


Solaris Motif


AIX Motif


HPUX Motif


Photon QNX


Mac OS X


You might have to update these paths for your version of Eclipse, such as changing 2.1.2 to 2.1.3. The current milestone build of Eclipse 3.0 uses 3.0.0.

Browse to swt.jar , click Open, and then click OK.

Some operating systems, such as Linux GTK, need more than one .jar file; in Linux GTK you use swt.jar and swt-pi.jar . You'll find all the required .jar files in the same folder.

8.3.4 See Also

Recipe 8.2 on creating an SWT application; Recipe 8.4 on launching an SWT application.

Eclipse Cookbook
Inside XML (Inside (New Riders))
ISBN: 596007108
EAN: 2147483647
Year: 2006
Pages: 232
Authors: Steve Holzner

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: