NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.0+)
}
int main(int argc, char *argv[], char **envp)
{
int res;
jclass cls;
jmethodID mid;
jobjectArray mainArgs;
JavaVM *jvm; /* denotes a Java VM */
JNIEnv *env; /* pointer to a native method interface */
JavaVMOption options[1];
JavaVMInitArgs vm_args;
options[0].optionString = "-Djava.class.path=."; /* where to find user classes */
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/*
* now start a Java VM
*/
res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
if (res != JNI_OK) {
fprintf(stderr, "Error %ld creating VM\n", res);
exit(1);
}
/*
* Find the Hello class and its method called "main"
*/
cls = (*env)->FindClass(env, "Hello");
if (cls == NULL) {
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
} else {
fprintf(stderr, "Hello class not found.\n");
}
exit(1);
}
mid = (*env)->GetStaticMethodID(env, cls, "main",
"([Ljava/lang/String;)V");
if (mid == NULL) {
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
} else {
fprintf(stderr, "No main method found in Hello class.\n");
}
exit(1);
}
/* Build argument array that will be passed to the Java method */
mainArgs = CreateStringArray(env, ++argv, --argc);
if (mainArgs == NULL) {
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
} else {