Hi All,
Does jdk 8 supports for jni also ?
Current case:
I’m building my project code using java 1.6 and ant 1.9, build is successful.
Target:
To build code on java 1.8 and ant 1.9
Failure:
Using jdk 1.8 currently the build is failing for test written in C
The code called is jni code and failure point is code (*javaEnv)->FindClass(javaEnv, name);
//not able to find the class file.Have manually verified that the .class file exists and jdk 1.8 is used in building that class.
on printing the exception using void ExceptionDescribe(JNIEnv *env);
Got exception:
Testing creation and use of custom properties...
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/xyz/api/MyClass : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
to check supported jni_version added code
#ifdef JNI_VERSION_1_4
printf("Version is 1.4 \n");
#endif
#ifdef JNI_VERSION_1_6
printf("Version is 1.6 \n");
#endif
#ifdef JNI_VERSION_1_8
printf("Version is 1.8 \n");
#endif
Only 1.4 and 1.6 is printed and not 1.8
From .class file verified that major version is 52.
So what I understand is basically class is compiled using java 8 and jni is trying to run using java 6 which is causing this issue.
From oracle docs on jdk 8 jni https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#version_information
https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#version_information
I see that only till IJDK/JRE 1.6, GetVersion()
returns 0x00010006
. is mentioned.
There is no reference of java 8
Where as in java 9 docs I see https://docs.oracle.com/javase/9/docs/specs/jni/functions.html
both java 8 and java 9 for jni is defined.
Can any one help on how to fix this issue?