UnsatisfiedLinkError in dynamically loaded class

I have a class which uses some native methods. It works fine when I build it into the jar file for my entire application.

I would like to make this class part of another jar file, and dynamically load the class when it is needed (using a URLClassLoader derivative). Doing it this way, the class is loaded, but when I reference the first native method, I get the UnsatisfiedLinkError.

I am calling System.loadLibrary(dllname), and it appears to be succesful (no exceptions thrown). I can even step into the class and debug it. And as I said, this all works fine when all classes are in the same jar. Any ideas what the problem may be? Thanks....

[672 byte] By [ryanmicj] at [2007-9-26 1:43:51]
# 1

I'm having the same problem with 1.4.2._02 on Windows 2000.

I already found two (not too satisfying) solutions to this problem:

1. Adding the jar to the classpath before running the application solved the problem.

But where's the point doing this, if you want to load it dynamically?

2. The "native class" in my jar is using classes from the main application (Interfaces, Exceptions, etc.). After removing these references / moving the referred classes into the jar file, the problem was also solved.

As said, these solutions are not very useful in a plug-in application.

On the other hand i still did not quite understand the problem itsef, so i'm stuck finding a solution.

come on Java Guru's: please help me out!

mb_0xffff at 2007-6-29 2:38:29 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

I found the solution myself.

I was using a utility method in my main application to map the library name to a fully qualified filename in the application's configurable library directory and then load it.

And i guess this was the problem, as the caller of the System.load() was not created by the classloader of the class that implemented the native methods.

After moving the call to there everything worked fine.

I don't recall reading about this problem. The JVM-Specification has only a brief chapter on "Binding".

Where can i find more information on this?

mb_0xffff at 2007-6-29 2:38:29 > top of Java-index,Java HotSpot Virtual Machine,Specifications...