#include <stdio.h>
#include "jni.h"
int main()
{
JavaVMOption options[1];
JNIEnv *env;
JavaVM *jvm;
JDK1_1InitArgs vm_args;
long status;
jclass
cls;
jmethodID mid;
jint square;
jboolean not;
options[0].optionString="-Djava.class.path=.";
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = 1;
vm_args.options = options;
status = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
if (status != JNI_ERR)
{
cls = (*env)->FindClass(env, "HelloWorld");
if (
cls != 0)
{mid = (*env)->GetStaticMethodID(env,
cls,"Test","(I)I");
if (mid != 0)
{square = (*env)->CallStaticIntMethod(env,
cls,mid,5);
printf("Result of int Method:%d\n", square);
(*jvm)->DestroyJavaVM(jvm);
return 0;
}
else
return -1;
}
#include <stdio.h>
#include "jni.h"
int main()
{
JavaVMOption options[1];
JNIEnv *env;
JavaVM *jvm;
JDK1_1InitArgs vm_args;
long status;
jclass
cls;
jmethodID mid;
jint square;
jboolean not;
options[0].optionString="-Djava.class.path=.";
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = 1;
vm_args.options = options;
status = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
if (status != JNI_ERR)
{
cls = (*env)->FindClass(env, "HelloWorld");
if (
cls != 0)
{mid = (*env)->GetStaticMethodID(env,
cls,"Test","(I)I");
if (mid != 0)
{square = (*env)->CallStaticIntMethod(env,
cls,mid,5);
printf("Result of int Method:%d\n", square);
(*jvm)->DestroyJavaVM(jvm);
return 0;
}
else
return -1;
}