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.
javac HelloWorld.java
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.
javac HelloWorld1.java
javah -jni HelloWorld3
gcc -dynamiclib HelloWorld2.c -I/System/Library/Frameworks/JavaVM.framework/Headers -o libHelloWorld5.jnilib
java -Djava.library.path=. HelloWorld3
- HelloWorld1
- In: javac command; as directory name of .java file.
- HelloWorld2
- In: gcc command to name source; as directory name of .c file.
- HelloWorld3
- 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;
- HelloWorld4
- Arbitrary message component
- HelloWorld5
- as part of shared library name provided in gcc command;
as string argument to System.loadLibrary in HelloWorld1.java;
With a parameter
JNI info:
Wikipedia
Perhaps the official Java Native Interface document
Programmer's Guide and Specification
IBM Tutorial
Mac:
Mac notes from Apple
Obstacles overcome
Apple Gold
Swig?