Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI_GetCreatedJavaVMs fails on Windows

843829Feb 21 2002 — edited Jun 6 2002
Folks,

On Windows, I am trying to load JVM into my application. But, I found strange behavior with JNI_GetCreatedJavaVMs function. I am using this function to find an already existing jvm (if any). If there is no JVM already created, I am using JNI_CreateJavaVM to create a new JVM. But, JNI_GetCreatedJavaVMs function always returns 65538. I tried with many samples but the result is same.Following is the sample code snippet
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
JNIEnv *env = NULL;

JavaVMInitArgs vm_args;
JavaVMOption options[4];
char a1,a2;
int nbOptions;
jint res = 0;
char classpath,librarypath;
JavaVM *vms=NULL;
jsize no_vms;
jsize buf_len = 1;

classpath = malloc(1024,sizeof(char));
librarypath= malloc(1024,sizeof(char));

strcpy(classpath, "-Djava.class.path=e:\\jdk1.2.2;e:\\jdk1.2.2\\jre\\lib\\i18n.jar");
strcpy(librarypath, "-Djava.library.path=.;e:\\jdk1.2.2\\jre\\bin;e:\\jdk1.2.2\\jre\\bin\\classic");

options[0].optionString = classpath;
options[1].optionString = librarypath;
options[2].optionString = "-Djava.compiler=NONE";
options[3].optionString = "-verbose:jni";

vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = JNI_TRUE;

res = JNI_GetCreatedJavaVMs(vms, 1, &no_vms);
if(res == 0 && no_vms == 0)
{
res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
}
----------------------------------------------------------------------------------
no_vms filled by JNI_GetCreatedJavaVMs is always 65538.
If don't use JNI_GetCreatedJavaVMs, JNI_CreateJavaVM successfully creates a new JVM.

Please, let me know if I am doing something wrong.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2002
Added on Feb 21 2002
4 comments
432 views