Created
August 26, 2012 05:54
-
-
Save md-5/3474757 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <jni.h> | |
JNIEnv* create_vm() | |
{ | |
JavaVM* jvm; | |
JNIEnv* env; | |
JavaVMInitArgs args; | |
JavaVMOption options[1]; | |
args.version = JNI_VERSION_1_2; | |
args.nOptions = 1; | |
options[0].optionString = "-Djava.class.path=c:\\projects\\local\\inonit\\classes"; | |
args.options = options; | |
JNI_CreateJavaVM(&jvm, (void **) &env, &args); | |
return env; | |
} | |
void invoke_class(JNIEnv* env) | |
{ | |
jclass helloWorldClass; | |
jmethodID mainMethod; | |
jobjectArray applicationArgs; | |
jstring applicationArg0; | |
helloWorldClass = (*env)->FindClass(env, "example/jni/InvocationHelloWorld"); | |
mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V"); | |
applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL); | |
applicationArg0 = (*env)->NewStringUTF(env, "From-C-program"); | |
(*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0); | |
(*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs); | |
} | |
int main(int argc, char **argv) | |
{ | |
JNIEnv* env = create_vm(); | |
invoke_class(env); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment