Java Reference
In-Depth Information
$ gcj -c SomeClass.java -o SomeClass.o
Files that do contain native methods are compiled with a command line
that looks like this:
$ gcj -fjni -c SomeClass.java -o SomeClass.o
That said, it does no harm to compile a source file that has no native
methods with the
-fjni
flag. This gives us a quick and dirty way to make our
library file.
$ find . -name "*.java" -exec gcj -fjni -c {} \; -print
Remember, you are in UNIX-land. Leverage your tools! In this case, the
advantage of using
find
is that, should the SWT source change (classes added
or removed), our “compile process” will handle it. Obviously, you can take this
in more sophisticated directions with
make
or
ant
. But this will get the job
done for us for now.
That will compile all of the SWT source.
20
Next, we want to assemble all
of 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
execution
quotes around our
find
command to get all of the
.o
filenames added to our
gcj
command that builds the shared library. For our final trick, we will compile
our
HelloWorld
class from the start of this chapter with
gcj
and our new SWT
shared library:
20. When we did this with Eclipse 2.1 GTK and
gcj
version 3.2.2, we had one compile error
where the return type of the
org.eclipse.swt.custom.TableCursor.traverse()
method was void, whereas the
Control.traverse()
method (from which
TableCursor
inherits) was boolean. So we hacked it. We changed the return type of
TableCursor.traverse()
to
boolean
and had it return
true
. We didn't test to see if this
was right! Use at your own peril!