Using JNI on the Macintosh


For a more extensive example of using JNI on the Macintosh see dtF/SQL Type 2 JDBC Driver in this MRJ developers collections.

Macintosh JNI folder ( download)
Self extracting Stuffit file which creates a folder containing a Metrowerks project, source code, JBinary applications and shared libraries for the "HelloWorld" and "Callbacks" examples.



HelloWorld.java

Project Settings for "HelloWorld"

HelloWorld.c

Project Settings for "HelloWorld Shared Library"


Callbacks.java

Project Settings for "Callbacks"

Callbacks.c

Project Settings for "Callbacks Shared Library"




HelloWorld JNI Examle Notes:

This is an example of JNI on the Macintosh it implements the classic "Hello world" example.

It should be noted that on the Macintosh this NOT a trivial example in that it requires the SIOUX console environment to be linked into the shared library. Also I have found out through much trial and error that mixing the SIOUX and MRJ consoles in the same application leads to very unstable applications.

The file "mrj_jni.h" supplied with the MRJ SDK contains the prototypes,

jint JNICALL JNI_SetStdOutProc(JavaVM* javaVM, jniConsoleProcPtr);
jint JNICALL JNI_SetStdErrProc(JavaVM* javaVM, jniConsoleProcPtr);
jint JNICALL JNI_SetStdInProc(JavaVM* javaVM, jniConsoleReadProcPtr);
which imply that all console output could be sent to a common console window. However I have not been able to use these API's to achieve that result.

This shared library is about 44 Kbytes.


Callbacks JNI Example Notes:

This is an example of JNI on the Macintosh it implements the classic "Callbacks" example.

The problem of mixing the SIOUX console with the MRJ console was describe in the file "HelloWorld.java". In order to eliminate both the problem of having two consoles as well as having to include the SIOUX environment in the shared library I extended the example to also use a callback method for printing to the MRJ console. That method is called "print".

This shared library is about 1 Kbytes.