Problem
I want to call Java code from my C/C++ program. What do I need in order to get this to work properly on OpenServer 5.0.x?
Some sample code of what this might look like is shown below: (JavaClass is the name of your Java class)
# include <jni.h>
# include <stdlib.h>main() {
JNIEnv *env;
JavaVM *jvm;
JDK1_1InitArgs vm_args;
jclass cls;JNI_GetDefaultJavaVMInitArgs(&vm_args);res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);cls=(*env)->FindClass(env,"JavaClass"); if(cls==0) printf("No Class Found\n"); else printf("Class Found...\n"); (*jvm)->DestroyJavaVM(jvm);
} Solution
This requires the UDK Feature Supplement 7.1.1b, the Java Developer Kit 1.2.2 and the appropriate compile line.
The UDK Feature Supplement 7.1.1b and the JDK 1.2.2 for SCO OpenServer 5 is available from SCO at the following URL:
http://wdb1.sco.com/clbk_web/owa/dwn_customerThese two products do require a license.
The correct compile line will vary greatly depending upon what you have included and require for your C/C++ program to function properly. Be sure you are using the correct compiler as well, /udk/usr/ccs/bin/cc is the correct one to use.
The following options must be present in your compile line:
/udk/usr/ccs/bin/cc -I /usr/java2/include -I /usr/java2/include/unixware/ \ -L/usr/java2/jre/lib/x86at/classic -L/usr/java2/jre/lib/x86at \ -L/usr/java2/jre/lib/x86at/green_threads \ -ljava -ljvm -lhpi -o <object_file> <file.c>
You must also set your LD_LIBRARY_PATH to the correct path:
LD_LIBRARY_PATH=/usr/java2/jre/lib/x86at:/usr/java2/jre/lib/x86at/classic:/usr/j
ava2/jre/lib/x86at/green_threads
export LD_LIBRARY_PATHThere have been many modifications to the UDK in the Feature
Supplement 7.1.1b. Without this Supplement installed, you may see
such errors as:i386ld values-xa.o: can't find library libjava.a i386ld values-xa.o: can't find library libjvm.a
ORundefined symbols:
libc_sigunlock _
libc_siglock See also
For an overview of the Java Native Interface (JNI), please visit the following URL:
http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html