views:

108

answers:

2

I need some help to handle following scenario.

I am using two applets which requires the same native library (.dll) file.

So when I run the applets from the web pages, for the first time first applet loads the dll into the applet class loader. It works fine. But when second applet tries to load the same dll it gives me exception saying that "Error loading win32com: java.lang.UnsatisfiedLinkError: Native Library C:\WINDOWS\system32\win32com.dll already loaded in another classloader"

I using following method to load the driver.

CommDriver driver = (CommDriver)Class.forName("com.sun.comm.Win32Driver").newInstance();
driver.initialize();

Please give me the solution

Thanks & Rgds, Rishikesh

A: 

You can not load native library in two different class loaders of same process.

Probably you must use shared library. I have not done anything like that.

Dheeraj Joshi
A: 

In short, the same _instance_ of the class that uses the native library must be shared by both classes.

You can do this by getting the system class loader (or the top parent of the class loader of your current class) and then dynamically have it load the class which uses the native library.

If you don't know which class does load the native library then you can make a proxy class and load this isntead. The class must call to the other libraries for you so they will be loaded with the Proxy classes classloader (and so also be shared).

However I would expect the security manager to prevent you from doing this within an Applet.

Joe
Hi Thanks for your quick assistance.I Used System.loadLibrary("win32com"); but i am getting the follwing exeption :javax.comm.NoSuchPortException at javax.comm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:105) Hence i load the driver using CommDriver driver = (CommDriver)Class.forName("com.sun.comm.Win32Driver").newInstance();driver.initialize();Is there any example of code where I can refer shared library stuff?
Rishikesh