Advertisement
caffeine314

JNI-FindClassProblem

Feb 11th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. int main( void )
  2. {
  3.     JavaVM *jvm;
  4.     JNIEnv *env;
  5.  
  6.     JavaVMInitArgs vm_args;
  7.     JavaVMOption*  options = new JavaVMOption[1];
  8.  
  9.     options[0].optionString = const_cast<char *>("-Djava.class.path=.");
  10.  
  11.     vm_args.version            = JNI_VERSION_1_6;
  12.     vm_args.nOptions           = 1;
  13.     vm_args.ignoreUnrecognized = false;
  14.     vm_args.options            = options;
  15.  
  16.  
  17.     int retVal = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
  18.  
  19.     if( retVal < 0 ) {
  20.         printf("VM was not created successfully.  Return code is %d.\n", retVal);
  21.         return -1;
  22.     } else
  23.         printf("VM was created successfully.\n");
  24.  
  25.     delete options;
  26.  
  27.  
  28.     jclass clsMain = env->FindClass("option/MainClass");
  29.  
  30.     if( clsMain == NULL ) {
  31.         printf("Can't find MainClass class.\n");
  32.         jvm->DestroyJavaVM();
  33.         return -1;
  34.     } else
  35.         printf("Found Main class.\n");
  36. ...
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement