JNI on Mac
The four lines below are shell commands that illustrate building and running a trivial JNI app.
This presumes stuff that comes along with Xcode 4.2 .
The first three command lines repectively produce files: HelloWorld.class, HelloWorld.h, libHelloWorld.jnilib.
javah -jni HelloWorld
gcc -dynamiclib HelloWorld.c -I/System/Library/Frameworks/JavaVM.framework/Headers -o libHelloWorld.jnilib
java -Djava.library.path=. HelloWorld
There are several name spaces above and it is not clear from the demo which HelloWorld tokens inhabit which spaces.
Below we try to substitute different names wherever we can to discover which namespaces there are.
javah -jni HelloWorld3
gcc -dynamiclib HelloWorld2.c -I/System/Library/Frameworks/JavaVM.framework/Headers -o libHelloWorld5.jnilib
java -Djava.library.path=. HelloWorld3
With a parameter
- In: javac command; as directory name of .java file.
- In: gcc command to name source; as directory name of .c file.
- as name of class provided in file HelloWorld1.java;
as name of instantiated class in HelloWorld1.java;
as string argument to javah command;
as name of header file produced by javah and included in HelloWorld2.c;
as munged name in C name space of C code to be invoked by JVM.
as class name provided to java command;
- Arbitrary message component
- as part of shared library name provided in gcc command;
as string argument to System.loadLibrary in HelloWorld1.java;
Perhaps the official Java Native Interface document
Programmer's Guide and Specification
Mac notes from Apple