JBI Component development (Part 4)
By Christophe Vaille on Nov 04, 2008
Java JNI Wrapper Library - JNIWrapper
1. The Java JNI Wrapper Library (JNIWrapper)
Java Native Interface (JNI) is a standard programming interface for writing Java native methods and embedding the Java virtual machine into native applications. The primary goal is binary compatibility of native method libraries across all Java virtual machine implementations on a given platform.
JNI Spec available at:
Components of the JNI library: MyLib:
- MyLib C. (MyLib.so or .dll)
- Java JNI Wrapper using native call to MyLib C. (JNIWrapper.jar)
- WSDL that describe the Java JNI Library interface. (MyLib.wsdl).
To create the JNIWrapper, use NetBeans and create a new Java project: JNIWrapper.
At the end of this topic the project will produce a JNIWrapper.jar file.
1.1.Build the JNIWrapper:
For this use case the native library is called MyLib and is written in C and provides 2 methods:
The parameter to define a rule in the getPolicyRule method is a C structure:
To wrap the C structure we use a Java class:
To map the two C methods with Java, we need to declare two java native methods:
Use the javah tool from the SDK to generate the .h that define the natice call:
Now you need to implement the source.c that include the .h generated by javah.
At the Java level we created the two methods that wrap the native call:
Our JNIWrapper is now ready, we need to create the WSDL file that define our JNIWrapper library.
1.2. Create the WSDL
The WSDL (MyLib.wsdl) will define two operations and a complex type as:
- getPolicyRule operation for the java method: getPolicyRule(String ruleName);
- setPolicyRule operation for the java method: setPolicyRule(PMRULE rule);
- Rule type for the java class PMRule.
See part 5 ...