File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes UnsatisfiedLinkError when using custom ClassLoader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "UnsatisfiedLinkError when using custom ClassLoader" Watch "UnsatisfiedLinkError when using custom ClassLoader" New topic

UnsatisfiedLinkError when using custom ClassLoader

Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

Hi All,
I have a really good problem here. Hopefully there is an expert out there that can help me figure it out or already has the answer.
I have built a custom ClassLoader extending the java.lang.ClassLoader. I use this ClassLoader (not important why I need it) to load a class X. This class X uses some native methods, so I load the dll with System.load("blah.dll"); inside Class X. Everything seems to work fine when I load class X, but intermittently I get an "UnsatisfiedLinkError: Native library <blah.dll> already loaded in another ClassLoader." There does not seem to be a pattern as to when this happens. Sometimes I can load class X 20 times before this happens, and sometimes only a few times. It's very strange. Is there a way to check if a dll is already loaded before trying to load it? I suppose I could catch the UnsatifiedLinkException, but then I don't know what to do once I've caught it. I could probably load the dll once at the beginning of the program, but I would like the load to happen inside class X for a more OO approach. Anyway, if anyone has any suggestions, I would love to hear.
Many many thanks!!
P.S. If I let JVM handle class loading, I don't get this problem at all.
I agree. Here's the link:
subject: UnsatisfiedLinkError when using custom ClassLoader
jQuery in Action, 3rd edition