To use some native C codes in java application, we need to create a jni interface. Let's see how we can create the jni C header file using javah.
1. Set up environment for build-up
1.1. Open console windows
1.2. Check whether javah is on your path. If not, refer below command.
>set path=%ProgramFiles%\Java\jdk1.6.0_17\bin;%PATH%
|
2. Compile java code. If you are using Eclipse and have no problem with compiling, just ignore the below line.
>java
Natives.java
|
3. Create a JNI C header file
3.1. Assuming that Navices.class file is located in the foler "bin\game\emulator\util\"
>javah -classpath bin -jni game.emulator.util.Natives
|
4. At last, we are ready to write the C function body.
4.1. To get correct method and signature, javap is a right tool. Output of below line will show the name and signature of Java native entities which can be accessed in C.
>javap -classpath bin -s -p game.emulator.util.
Natives
|
Other useful link: Calling Java methods