Wednesday, October 24, 2007

Java Native Interface [ JNI ]

JNI is an acronym of Java Native Interface. It is an programming framework for Java software developer to interact with native libraries which were written in some other languages, such as C, C++ ... etc.

The usability of the JNI comes into picture when a Java software developer try to use some of the native or open source libraries which were written in languages other than Java.

I was working on project of similar kind of requirement. The project which I worked the requirement was something like, replacing the Quicktime for Java library with native Quicktime library APIs. The entire project code was in Java. Quicktime for Java library is actually a provides some higher level APIs which intern calls the native Quicktime APIs. Some times this renders some performance issue while running the Java application. And also this lacks some features and is not as good as the native Quicktime library.

The project which I worked was on Mac platform. In that project we developed a JNI shared library which is wrapper layer over Quicktime Mac library.

Start up with the project:

Generate a C header file from the Java class using the below command:

javah [optionns] java_classname

Create a jni library target in your Java application. Add all the source and header files to your newly created target. Final step is that implement all the methods in the header file which was created by javah using your native library.

Load the created the jni shared library from your Java application.

Here I did not mention all the steps in detail. If you find any difficulty in understanding the concept and steps, please raise your comments in the comments column.

If anybody working on the similar requirement, and got struck at any point please share with me through comments. I will try to shed some lights on your issue.

Below is the link to sample code:
http://developer.apple.com/samplecode/MyFirstJNIProject/

Yours,
Satish

0 Comments:

Post a Comment

<< Home