13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

17.4 SWT and GCJ397$ gcj -c SomeClass.java -o SomeClass.oFiles that do c<strong>on</strong>tain native methods are compiled with a command linethat looks like this:$ gcj -fjni -c SomeClass.java -o SomeClass.oThat said, it does no harm to compile a source file that has no nativemethods with the -fjni flag. This gives us a quick and dirty way to make ourlibrary file.$ find . -name "*.java" -exec gcj -fjni -c {} \; -printRemember, you are in UNIX-land. Leverage your tools! In this case, theadvantage of using find is that, should the SWT source change (classes addedor removed), our “compile process” will handle it. Obviously, you can take thisin more sophisticated directi<strong>on</strong>s with make or ant. But this will get the jobd<strong>on</strong>e for us for now.That will compile all of the SWT source. 20 Next, we want to assemble allof the object files produced into a shared object.$ gcj -shared -o swt.so $(find . -name "*.o" -print)Once again, we leverage our tools. This time, we use bash executi<strong>on</strong>quotes around our find command to get all of the .o filenames added to ourgcj command that builds the shared library. For our final trick, we will compileour HelloWorld class from the start of this chapter with gcj and our new SWTshared library:20. When we did this with Eclipse 2.1 GTK and gcj versi<strong>on</strong> 3.2.2, we had <strong>on</strong>e compile errorwhere the return type of the org.eclipse.swt.custom.TableCursor.traverse()method was void, whereas the C<strong>on</strong>trol.traverse() method (from whichTableCursor inherits) was boolean. So we hacked it. We changed the return type ofTableCursor.traverse() to boolean and had it return true. We didn’t test to see if thiswas right! Use at your own peril!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!