MozillaZine

Raptor Engine Successfully Embedded in Java!

Sunday April 25th, 1999

From Edwin Woudt and arielb comes cool news! A gentleman named Kirk Baker has successfully embedded the Gecko layout engine in Java. Click here for details.


#7 Re:Raptor Engine Successfully Embedded in Java!

by Chris Knoll <knoll@eclipse.net>

Tuesday April 27th, 1999 11:15 AM

You are replying to this message

Here is how JNI works:

First, you have a set of functions in a library (I'm sure Raptor.dll has a whole slew of them). You make this library on the target platforms (raptor.dll on Win32, and libraptor.so on linux). Now, these 2 libs prolly won't have the same code (definitely not the same binaries) but they will both contain the same method calls (or, maybe not, more on this later). Then, put this lib aside for a while.

Next, you write the Java classes that encapsulate the functions located in the raptor lib. All the methods in these Java classes will be declared 'native'. You would make multiple Java classes to logically group all the functionality in the Raptor lib. Also, in the constructor of the class, put a call to System.loadLibrary("jniraptor") (remember this name!)

Next, you use the javah on the new classes to generate the header files that will be used in writing the C++ to Java interface. Then, you create a new C++ file that includes the generated header files (along with some other necessary JNI header files), and you hookup the JNI calls to their appropriate native calls located in the Raptor lib. Then you comple this code into a linkable library. Call it libjniraptor.so on linux, and jniraptor.dll on win32 (this is important naming convension!). (the jniraptor part is the important. On the Linux JVM, the JVM will look for libjniraptor.so when loadLibrary("jniraptor") is called, on a Win32 JVM, it will look for jniraptor.dll, and it will serch the SYSTEM PATH not the CLASSPATH!)

Now, as far as the drawing routines (this is a rendering engine, after all), I have no idea how that was done. I'm sure he made a class wrapper for the Raptor functionality and subclassed it from component (or panel) so that it can be used as a drawing surface inside of Java, but I'm not sure how he got the native code to draw to the Java panel (if he even has done that!) Anyways, I hope this sheds some light.