JNI start jvm with unicode support
I am using the invocation api to load and run a jvm within C code. I am using the java structure JavaVMOption to do this. In specific I am using its element char *optionString to specify my -Dbs.prefsdir="c:\\develop\\XXXXChineseMixedLationCharsXXXX\\" where bs.prefdir is the path can be defined by user.
What I am doing is straight out of the java examples and it works fine right upto the point where I need to use a wide-character/unicode path - I can not do it, because optionString is a char* not a wchar_t*. Anybody know how to get around this? Solutions should be restricted to JDK 1.6 and lower.
I have read carefully JNI documentation: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html#wp633
char *optionString; /* the option as a string in the default platform encoding */
I have read part of the eclipse executable launcher source code, there it did something like convert wide char to multibyte chars with default code page:
int byteCount = WideCharToMultiByte (CP_ACP, 0, (wchar_t *)src, -1, NULL, 0, NULL, NULL); char *dest = malloc(byteCount+1); dest[byteCount] = 0; WideCharToMultiByte (CP_ACP, 0, (wchar_t *)src, -1, dest, byteCount, NULL, NULL); return dest;
I have tried treating the optionString as a multibyte character string using the code above and this does not work. I have tried treating it as unicode itself, but this doesnt work either. Does anybody have a solution for this please?
Arguments passed to the JNI_CreateJavaVM are in the platform's default encoding, so I don't believe you will be able to pass a wide-byte character string into the JavaVMOption struct.
Try Holger's suggestion of setting the system property with a jstring of the proper encoding style, after creating the JVM.