GeeCON Prague 2014*
The moose likes Other JSE/JEE APIs and the fly likes Linking JNI code to JVM.dll file.......Getting Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Linking JNI code to JVM.dll file.......Getting Error" Watch "Linking JNI code to JVM.dll file.......Getting Error" New topic
Author

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

vimalkeshubhai chaudhari
Greenhorn

Joined: Dec 14, 2009
Posts: 3
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 27, 2005
Posts: 19697
    
  20

And I'll move this further along to Other JSE/JEE APIs which is where we discuss JNI.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: Linking JNI code to JVM.dll file.......Getting Error