DavidRumins: towcker7

File towcker7, 2.6 KB (added by johnstod, 12 years ago)

How to Write, Compile and Execute a SWT Application

Line 
1How to Write, Compile and Execute a SWT Application
2===================================================
3===================================================
4
5
6Introduction
7============
8
9I have spent today looking at SWT and Eclipse as potential
10technologies for WCKER's implementation.
11
12SWT is a replacement GUI API for Java (instead of the usual
13AWT/Swing) and Eclipse is an integrated IDE for Java development
14which can also do CVS stuff.
15
16For "looking at", read "trying to get to work" ! :-)
17I didn't help that the instructions in the online tutorials
18are wrong, and the standard tutorial example does not itself
19work. Finally, I managed to find an online forum where some
20of these issues were discussed ..... phew!!!!!!
21
22The next section documents my hard-won findings of how to
23produce a working SWT application.
24
25
26Developing a SWT application
27============================
28
29Source Code
30-----------
31
32import org.eclipse.swt.widgets.*;
33import org.eclipse.swt.*;
34/**/
35public class SWTHello {
36        public static void main(String[] args) {
37
38                MessageBox m = new MessageBox(new Shell());
39                m.setMessage("Hello, World");
40                m.open();       
41        }
42}
43
44Compilation
45-----------
46
47javac -classpath /usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt.jar:/usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt-pi.jar SWTHello.java
48
49Notes:
50        (1) Only one of the two necessary JAR files was mentioned in the tutorials.
51        (2) /usr/eclipse is the local installation root of Eclipse
52        (3) It is also possible to supply these command line arguments through
53            the CLASSPATH environment variable.
54
55Execution
56---------
57
58java -classpath /usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt.jar:/usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt-pi.jar:. -Djava.library.path=/usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/os/linux/x86/ SWTHello
59
60Note:
61
62        (1) As SWT also uses a native (i.e. 'C') library, then one has to not only specify where Java
63            objects can be found but also 'C' objects i.e. more variables to get wrong.
64
65        (2) It is also possible to supply these command line arguments through
66            the CLASSPATH and LD_LIBRARY_PATH environment variables.
67
68
69Conclusion
70==========
71
72I am able now to build and run small SWT applications, both inside and outside the
73Eclipse IDE. Only the command-line solutions are provided for succinctness. The next
74stage is to assess the ease of implementing some initial WCKER pages in SWT.
75
76Eclipse also contains an interactive graphical Java debugger (to be checked out): this is
77particularly good news (fingers crossed) as the stand-alone Java debuggers I tried out earlier
78in the project were universally poor!
79
80
81                                David