Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

JNI_CreateJavaVM question

Thread view: 
Tim  Wong - 21 Jun 2005 17:57 GMT
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
Andrew Thompson - 21 Jun 2005 18:16 GMT
> ..but I have a feeling that the JVM on my machine is only
> 1.4.x.

Replace feelings with facts.
<http://www.physci.org/pc/property.jsp?prop=java.version>

Download JTest jar to check what version of Java is running
by default on the desktop (the web page applet will tell you
what the browser is using).

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Tim  Wong - 21 Jun 2005 18:40 GMT
I've tried it and it says i'm running version 1.5

So if the JVM is not the issue...then what is?
Andrew Thompson - 21 Jun 2005 19:01 GMT
> 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?..

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Chris Uppal - 22 Jun 2005 09:26 GMT
Tim Wong wrote:

> 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
Tim  Wong - 24 Jun 2005 16:03 GMT
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
Gordon Beaton - 24 Jun 2005 16:16 GMT
> 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

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Tim  Wong - 24 Jun 2005 16:25 GMT
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!
Lucy - 22 Jun 2005 19:45 GMT
> Hello All!
>
[quoted text clipped - 10 lines]
>
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.