Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > dll loading problem

Reply
Thread Tools

dll loading problem

 
 
Dmitry Yukelson
Guest
Posts: n/a
 
      09-07-2004
Hi all,

I'm trying to create an interactive application which compiles ant
file, and does several other things.
For this purpose I'm using Project and ProjectHelper ant classes.
In addition, I defined my own ant Task, which used native code:

public class IdentityTask extends MatchingTask {
....
private native boolean CallIdentity();

static {
System.loadLibrary("...");
}
......
}


The first compilation is succeeded without any problems, the dll is
loaded and the native code is called. But when the second compilation
request is processed, the following exception is thrown:
>>>>sample.xml java.lang.UnsatisfiedLinkError: Native Library ....

already loaded in another classloader

Thanks in advance
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      09-07-2004
On 7 Sep 2004 04:08:07 -0700, Dmitry Yukelson wrote:
> For this purpose I'm using Project and ProjectHelper ant classes. In
> addition, I defined my own ant Task, which used native code:
>
> public class IdentityTask extends MatchingTask {
> ....
> private native boolean CallIdentity();
>
> static {
> System.loadLibrary("...");
> }
> .....
> }
>
> The first compilation is succeeded without any problems, the dll is
> loaded and the native code is called. But when the second compilation
> request is processed, the following exception is thrown:
>>>>>sample.xml java.lang.UnsatisfiedLinkError: Native Library ....

> already loaded in another classloader


The exception says that you attempted to load the same class (and
consequently, its native library) a second time while the initial
library was still loaded.

I don't know how Ant tasks are structured, or how Ant assigns
classloaders to them etc, however the following holds in general when
you use native code in your application:

- any given native library can only be loaded once
- a native library can't be unloaded explicitly by your code, and
won't be unloaded by the JVM until its classloader is garbage
collected.

So you need to ensure that your classes with native methods are loaded
high enough in the classloader hierarchy that they are visible to any
other classes that will need them.

In your case, you could consider factoring out the native part into a
class of its own that you can load separately (once), and then make
calls to it from your IdentityTask.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine if a DLL is a COM DLL or .NET DLL Anushi ASP .Net 5 10-28-2004 01:59 PM
Why does Ruby use both tcl83.dll and tk83.dll (instead of just tk83.dll)? H. Simpson Ruby 4 08-03-2004 04:45 PM
mprapi.dll --> samlib.dll --> ntdll.dll issue. Some1 Computer Support 4 04-05-2004 02:02 AM
ASP.NET: problem loading managed C++ DLL =?Utf-8?B?TkdN?= ASP .Net 2 02-09-2004 10:42 PM
msvcrt.dll, msvcirt.dll, msvcrt20.dll and msvcrt40.dll, explanation please! Snoopy NZ Computing 16 08-25-2003 12:34 PM



Advertisments