Recipe 8.4 Launching an SWT Application

     

8.4.1 Problem

You want to launch your SWT application.

8.4.2 Solution

You need to tell the JVM where to find the Java Native Interface (JNI) code support for SWT when launching an SWT application. Here's the argument you supply when you run an SWT application (as before, HOMEDIR is the directory in which you installed Eclipse, and you should update these paths to match your version of Eclipse. For example, 2.1.2 should become 2.1.3 or some other version number):


Win32

-Djava.library. path =HOMEDIR\eclipse\plugins\org.eclipse.swt.win32_2.1.2\ os\win32\x86


Linux GTK

-Djava.library.path=HOMEDIR/eclipse/plugins/org.eclipse.swt.gtk_2.1.2/os/ linux/x86


Linux Motif

-Djava.library.path=HOMEDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.2/ os/linux/x86


Solaris Motif

-Djava.library.path=HOMEDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.2/ os/solaris/sparc


AIX Motif

-Djava.library.path=HOMEDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.2/ os/aix/ppc


HPUX Motif

-Djava.library.path=HOMEDIR/eclipse/plugins/org.eclipse.swt.motif_2.1.2/ os/hpux/PA_RISC


Photon QNX

-Djava.library.path=HOMEDIR/eclipse/plugins/org.eclipse.swt.photon_2.1.2/ os/qnx/x86


Mac OS X

-Djava.library.path=HOMEDIR/eclipse/plugins/org.eclipse.swt.carbon_2.1.2/ os/macosx/ppc

8.4.3 Discussion

Even after you've compiled as SWT application, you still need to complete another step before you're ready to roll. You have to tell the JVM where to find the native code support for SWT with an argument to the JVM.

To launch the SWT application we've been developing in the previous two recipes, select the class you want to run, FirstSWTClass , in the Package Explorer, and select Run Run to set up a launch configuration.

In the Launch Configurations dialog, select Java Application, and click the New button. The Name , Project, and Main class boxes should be filled in automatically; if they aren't, fill them in. Then click the Arguments tab. In the "VM arguments" box, enter the JVM argument as shown earlier (see Figure 8-3).

Figure 8-3. Setting up an SWT launch configuration
figs/ecb_0803.gif

Then click the Apply button, followed by the Run button. You should see this new example at work, as shown in Figure 8-4.

Figure 8-4. Running an SWT application
figs/ecb_0804.gif

Congratulationsyou're an SWT developer.

8.4.4 See Also

Recipe 8.2 on creating an SWT application; Recipe 8.3 on setting Eclipse's build path to use SWT; Chapter 7 of Eclipse (O'Reilly).



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

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net