JNI call doesn't work in Java 6
I have an old application with a single JNI class in it. It has been working for years under Java 1.4 and Java 1.5. We're trying to transition to to Java 1.6, but we've run into the following error:
WARNING: exception in listener: java.lang.NoClassDefFoundError: JniAdapter
java.lang.NoClassDefFoundError: JniAdapter
at com.mycompany.JniAdapter.jniDoSomething(Native Method)
at com.mycompany.JniAdapter.doSomething(JniAdapter.java:264)
. . . // down to event dispatcher where the warning comes from
Well, it seems the NoClassDefFoundError is somehow missing the fully qualified class name with the package name. So let me describe the file layout, in case it matters:
* app\run.bat (calls %JAVA_HOME%\bin\java.exe cp- Classes com.mycompany.Main)
* app\JniAdapter.dll
* app\Classes\com\mycompany\JniAdapter.class
* app\Classes\com\mycompany\Main.class
Again, this works great in Java 1.4 and 1.5, without recompiling (not to say I haven't tried recompiling it under Java 6).
So... What changed in 1.6 with respect to JNI class lookup and what is the fix?
Anm
[1145 byte] By [
Anma] at [2007-11-27 6:31:07]

# 3
> It is a class path error, so why do you expect that
> it has anything to do with JNI?
1. Because the classpath to the .class file doesn't change just because I run in Java 1.6.
2. Because the class it should be looking for is already loaded, and is even in the error stack trace.
The error is more subtle than just a bad classpath. It is trying to load a class without the fully qualified name, and thus cause the NoClassDefFoundError when the ClassLoader (unsurprisingly) can't find the class by the incorrect name. My question is, why is it looking for JniAdapter instead of com.mycompany.JniAdapter.
I only assume the error is JNI related because it found the class when referenced from other Java classes.
Anma at 2007-7-12 17:55:59 >

# 4
> I only assume the error is JNI related because it
> found the class when referenced from other Java
> classes.
The class is loaded once. If the load fails then you get that error. If it doesn't load then you can't use it anywhere (excluding different class loaders.)
Now if you are using a static initializor block to load the class and the dll fails to load then I believe it will fail to load the class. If that is the failure reason then you would still get the full name.
You can just comment out the load call and see what happens.