RFasioli
RFasioli

Reputation: 129

Creating a java7 JVM with the JNI invocation API

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?

Upvotes: 5

Views: 5531

Answers (2)

Juan Carlos Kuri Pinto
Juan Carlos Kuri Pinto

Reputation: 1144

For Mac users, I highly recommend to read this article:

How do I switch between Java 7 and Java 6 on OS X 10.8.2? https://superuser.com/questions/490425/how-do-i-switch-between-java-7-and-java-6-on-os-x-10-8-2

I successfully compiled and ran the JNI example in which I call some static methods from a Java class I created. I solved the problem by invoking "java_home" like this:

/usr/libexec/java_home -v 1.6.0_45 --exec javac Sample.java

Upvotes: 2

RFasioli
RFasioli

Reputation: 129

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

Upvotes: 1

Related Questions