JNI_CreateJavaVM question

T

Tim Wong

Hello All!

I am bumping into a problem where JAR's supplied to me were compiled
using JDK 1.5, but I have a feeling that the JVM on my machine is only
1.4.x. That being said...when I use JNI in my C++ code, I'm getting
the following exception

No JVM is running;java.lang.UnsupportedClassVersionError:
com/test/Buffer (Unsupported major.minor version 49.0)

Can JNI experts out there direct me on how to load the proper JVM
version in c++?

Thanks,

Tim
 
T

Tim Wong

I've tried it and it says i'm running version 1.5

So if the JVM is not the issue...then what is?
 
A

Andrew Thompson

I've tried it and it says i'm running version 1.5

Cool. We now have one more (small) part of this
puzzle locked down.
So if the JVM is not the issue...then what is?

...err. Well, for that you might need to enlist the
help of one of the JNI gurus. Gordon? Jon?..
 
C

Chris Uppal

Tim said:
No JVM is running;java.lang.UnsupportedClassVersionError:
com/test/Buffer (Unsupported major.minor version 49.0)

Can JNI experts out there direct me on how to load the proper JVM
version in c++?

You will have to provide more detail. What OS are you running on -- this is
OS-dependent stuff ? How are you loading the JVM dynamic library into your
application ? From explicit code, or implicitly in some way ?

You are certainly correct that the "Unsupported major.minor version 49.0" error
is indicative of attempting to load a 1.5-compiled classfile into a pre-1.5
JVM. But, since you also said that you have 1.5 installed on the machine in
question, the problem must be that your code is loading the wrong DLL (or
equivalent). It is impossible (for me) to guess /why/ that is happening
without more detail. BTW, it would also help if you mention whether you
yourself are familiar with loading dynamic libraries from C++ in general (not
just the JVM).

-- chris
 
L

Lucy

Tim Wong said:
Hello All!

I am bumping into a problem where JAR's supplied to me were compiled
using JDK 1.5, but I have a feeling that the JVM on my machine is only
1.4.x. That being said...when I use JNI in my C++ code, I'm getting
the following exception

No JVM is running;java.lang.UnsupportedClassVersionError:
com/test/Buffer (Unsupported major.minor version 49.0)

Can JNI experts out there direct me on how to load the proper JVM
version in c++?

Thanks,
I have recently had a problem very similar to this. I just installed 5.0
so my class files were 5.0 class files. This corresponds to major.minor
version 49.0
I think major.minor 46.0 corresponds to 1.4.2
Anyway, the "java" command that was running was in my path and was from
version 1.4.2
I changed the path to use the "java" command from version 5.0 and everything
is fine.
 
T

Tim Wong

I'm running on Windows 2K Pro, loading a JAR file with VC++ 6.0

Here's the code inside the methods which loads the JVM and tries to
locate the classes....
Unfortunately, I don't have the source to recompile the Test.jar
(otherwise I could probably just recompile).

bool JARLoader::LoadJavaClass( )
{
...
JNIEnv* pEnv = NULL;
jint jResponse;
JavaVM* m_pJVM = NULL;
JavaVMInitArgs vm_args;
JavaVMOption options[3]; // java command line options needed

CString sOption1("-Djava.class.path="
"C:\\JavaProjects\\Test.jar;");
char* cOption1 = new char[sOption1.GetLength() + 1];
strcpy(cOption1, sOption1);

options[0].optionString = cOption1;
options[1].optionString = "-Djava.compiler=NONE"; // disable the
JIT compiler
options[2].optionString = "-verbose:jni"; // enable verbose
messages from jni
...
...
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 4;

jResponse = JNI_CreateJavaVM (&m_pJVM,
reinterpret_cast<void**>(&pEnv), &vm_args);

if (jResponse != JNI_ERR) {
delete cOption1;
jResponse = pEnv->PushLocalFrame(6);

if (jResponse != JNI_ERR) {
LoadJavaClass ();
}
} else AfxMessageBox("Can't Start JVM\n");
}

void JARLoader::LoadJavaClass()
{
jclass WirelessTokenClass = pEnv->FindClass
("test/blah/TestLoadClass");

if (WirelessTokenClass != NULL){
AfxMessageBox("TestLoadClass Found\n");
}
else{
pEnv->ExceptionDescribe();
AfxMessageBox("Can't FindClass TiccExecutor\n");
}
}


The exception I get (when retrieved by pEnv->ExceptionDescribe())

java.lang.UnsupportedClassVersionError: xxx/xxx/xxx/TestRootClass
(Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

Any help would be appreciated
 
G

Gordon Beaton

I'm running on Windows 2K Pro, loading a JAR file with VC++ 6.0

Here's the code inside the methods which loads the JVM and tries to
locate the classes....

I haven't really been following this thread, but I believe the answer
to your original question (which JVM will run) depends on how you link
your launcher to the appropriate libraries that the JVM consists of.

You can either specify link options when you build the launcher, or
rely on e.g. PATH or registry settings at runtime. I am not a windows
user so I can't give more specific advice here, but this might give
you an idea of what to look for.

One other thing, probably unrelated:
JavaVMOption options[3]; // java command line options needed
[...]

vm_args.options = options;
vm_args.nOptions = 4;

I count only three.

/gordon
 
T

Tim Wong

Success...I changed the PATH var to point to a newer JVM than what was
currently pointing to. The funny thing I'm not sure I understand was
why it told me my JVM was 1.5...when it really wasn't.

Thanks All!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top