|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 7 of 7
All of these files are available for download from Resources:
main.c is the main executable and the application's native part. It covers the creation of the Motif GUI, the OpenGL rendering,
and the JVM startup using JNI. It also behaves as a socket server.
SwingMenu.java implements the Swing part of the GUI. It also behaves as a socket client. Finally, it calls native methods, which are implemented in the nativeMethods.c file. Using the javah tool with SwingMenu.java, you also obtain a SwingMenu.h file. SwingMenu.h defines the prototypes for all the native methods in SwingMenu.java.
nativeMethods.c implements the methods defined native in SwingMenu.java. It handles the underlying windowing issues and also calls back functions defined in the main executable.
Now, I'll shed some light on how the application is built and the runtime dependencies:
The main executable named swing-motif is built from main.c and must link with the libjvm.so library, which implements the JNI API and the JVM. At runtime the LD_LIBRARY_PATH must point to the directory where that library is located (on Solaris, it is usually /usr/java/jre/lib/sparc).
Compiling SwingMenu.java with javac produces the SwingMenu.class file. The JVM loads it when you call FindClass() from the main executable. Nevertheless, it is your responsibility to tell the JVM the location of the .class file. To do so, specify the classpath in the arguments provided to the JVM at startup (see Listing 1).
nativeMethods.c is built into a dynamic library named libnativeMethods.so. As mentioned before, this library must link to libjawt.so. Library libnativeMethods.so is loaded explicitly in the SwingMenu class. In fact, the JVM completes the job on behalf of the Java class. That is why you must specify where the libnativeMethods.so library is located in the JVM startup arguments. Do that by setting the libraryPath to the proper value (see Listing 1).
Finally, to build the application on Solaris, just copy the three source files mentioned above and the Makefile file in the same directory. Then run make to build the swing-motif executable, the SwingMenu.h header file, the libnativeMethods.so library, and the SwingMenu.class byte code. To start the application, just run the run.ksh script.
The buildtime/runtime requirements are as follows:
You have learned how to start a JVM from a legacy application, create Java objects from a legacy application, call back legacy code from Java using a thread-safe architecture, and integrate a Swing GUI with a legacy application using X11, Motif, and OpenGL. The architecture described above helps you achieve the best of both worlds -- Swing and your legacy apps -- without jeopardizing your current assets. In closing, before starting any new development projects, remember that Java runs on many operating systems and is the state-of-the-art development environment for multiplatform support.
Read more about Core Java in JavaWorld's Core Java section.