We have a class in java 7 and need to load it from native code. I have already used java 6 with JNI but java 6 can’t load that class. So I installed the new JDK, changed include directories and link references in my VC project etc. All was well until I wanted to start the jre7 from JNI:
JNI_CreateJavaVM takes the the java version in vm_args.version parameter but there’s no definition for a newer version than 1.6.
JavaVMInitArgs vm_args;
...
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 2;
vm_args.options = options;
vm_args.ignoreUnrecognized = 0;
int ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
Calling FindClass for the java7 class obviously produces an UnsupportedClassVersionError.
The problem: How do I create a java7 JVM with JNI_CreateJavaVM?
The problem are on path environment variable, that’s refers to jre6 before jre7.
On visual C++->Property Pages->Debugging->Environment, I changed to:
path=C:\Java\jre7\bin;C:\Java\jre7\bin\client;%path%
Or directly on: My Computer->Properties->Advanced->Environment Variables