java - JNI FindClass can't find class which uses jar -


i'm working on project java functions must called c++ code using jni. i've tried simple java class, when i'm starting use .jar in java project jni's findclass function can't find class. i've done research , read classpath needed compiling .java file if uses libs, findclass returns null in case. here's basic structure of code

javavmoption options[2]; jnienv *env; javavm *jvm; javavminitargs vm_args; long status; jclass cls; jmethodid mid; jint square; jboolean not;  options[0].optionstring = "-djava.class.path=<path_to_my_java_class>"; options[1].optionstring = "-djava.library.path=<path_to_my_jar_file>"; memset(&vm_args, 0, sizeof(vm_args)); vm_args.version = jni_version_1_6; vm_args.noptions = 2; vm_args.options = options; status = jni_createjavavm(&jvm, (void**)&env, &vm_args);  if (status != jni_err) {     cls = env->findclass("package/classname"); //returns null while using jar     if(cls != 0)     {            //do stuff     }     jvm->destroyjavavm();     return 0; } else     return -1; 

any ideas?

updated: i've tried

options[0].optionstring = "-djava.class.path=<path_to_my_java_class>;<path_to_jar>";      options[0].optionstring = "-djava.class.path=<path_to_my_java_class>";     options[1].optionstring = "-classpath <path_to_jar>"; 

i think mistake putting jar on "library.path". library path path finding native libraries ... not jar files.

you should put jar file on classpath; e.g.

    options[0].optionstring =          "-djava.class.path=<path_to_my_java_class>:<path_to_my_jar_file>"; 

(on windows, use ";" classpath separator instead of ":".)


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -