Troubleshooting
Problem
One of the main reasons that a Java program receives a java.lang.UnsatisfiedLinkError() is a mismatch in names between the JVM and the Service Program. This document describes how to determine the correct naming.
Resolving The Problem
Symptom: Java program that uses JNI Program on IBM i to call a native function from Service Program fails with java.lang.UnsatisfiedLinkError().
The important link between the JVM and the native method being called is the name of the native method. The name exported by your service program must match the name expected by the JVM; otherwise, one of the call-time (as opposed to load-time) UnsatisfiedLinkError is thrown.
The name that is created by the JVM (the caller side) must match the name that is exported from MYSRVPGM (the callee).
To see the name that Java creates, do the following:
Start a QSH session and type
javah -jni fully.qualified.class.name
where the fully.qualified.class.name is the name of your class (without the '.class' on the end.) This creates a file in the current directory called fully_qualified_class_name.h that includes the "name" that the JVM will be using to get to the native method.
Example
javah -jni java.lang.String
...results in the file java_lang_String.h
Then, java.lang.String specifies a native method, "intern()", and the section of this header file describing it looks similar to the following:
/*
* Class: java_lang_String
* Method: intern
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_java_lang_String_intern
(JNIEnv *, jobject);
The important part is the part after JNICALL -- the Java_java_lang_String_intern. This is the name a native method library (also known as the service program) designed to handle this native method must export to make the connection.
To see the names exported by MYSRVPGM, on the operating system command line type the following:
DSPSRVPGM SRVPGM(MYSRVPGM) DETAIL(*PROCEXP)
Press the Enter key.
Historical Number
335997894
Was this topic helpful?
Document Information
Modified date:
18 December 2019
UID
nas8N1016124