• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linking JNI code to JVM.dll file.......Getting Error

 
vimalkeshubhai chaudhari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to link JVM.dll with my JNI code to create a runtime environment........
But when I am executing this code, the function JNI_CreateJavaVM returns -1 which specifies that JVM creation is failed......

Can anyone please suggest where I am going wrong?

I am posting the JNI code :


int JavaAPI(ServerParameter* servParams, int i) {
char* (*lib_func)() = 0;
jint (*lib_func2)()= 0;
JNIEnv *env= NULL;
JavaVM *jvm= NULL;
JavaVMInitArgs vm_args;
JavaVMOption options[5];
jclass cls;
jmethodID mid;
jstring jstr1,jstr2,jstr3,jstr4,jresult;
jobjectArray args;
const char* tempstr;
jsize bufLen = 1;
jsize nVMs=0;
jint res, resCheckVM;
void *thr_args;
char clspath[400]="-Djava.class.path=";

resCheckVM = JNI_GetCreatedJavaVMs(&jvm, bufLen, &nVMs);
if( resCheckVM < 0 || nVMs < 1 )
{
vm_args.version = JNI_VERSION_1_6;
vm_args.options = options;
vm_args.nOptions = 5;
vm_args.ignoreUnrecognized = JNI_FALSE;
options[0].optionString = "-Xms4M";
options[1].optionString = "-Xmx64M";
options[2].optionString = "-Xss512K";
options[3].optionString = "-Xoss400K";
strcat(clspath,servParams[i].path);
options[4].optionString = clspath;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
fflush(stdout);

res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args); //here JNI_CreateJavaVM is returning -1,due to which JVM creation is failing
if (res < 0)
fprintf(stderr, "Failed to Create JVM.\n");
}
else
{
fflush(stdout);
res = (jvm)->AttachCurrentThread((void**)&env, NULL);
if (res < 0)
fprintf(stderr, "Failed attaching current thread to JVM.\n");
}

cls = (env)->FindClass(servParams[i].lib);
//cls = (env)->FindClass("SSOClass");
if (cls == 0)
{
fprintf(stderr, "Can't find Prog class %s\n",servParams[i].lib);
return 1;
}

.
.
.
.
.
}
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.

Nothing to do with testing; moving to more appropriate forum.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I'll move this further along to Other JSE/JEE APIs which is where we discuss JNI.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic