Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java.lang.UnsatisfiedLinkError: Can't load library from JNI code

Reply
Thread Tools

java.lang.UnsatisfiedLinkError: Can't load library from JNI code

 
 
shivaraj
Guest
Posts: n/a
 
      01-11-2007
Hi,
I am using "System.load("C:/sampleDLL2");" funtion to load a library.
But getting
Caused by: java.lang.UnsatisfiedLinkError: Can't load library:
C:/sampleDLL2
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.appiq.providers.win32.Win32MailBoxCache.<clini t>
(Win32MailBoxCache.java:112)
error. Could any one tell me the reason please?

I tried using System.loadLibrary("sampleDLL2") method but here there
also I am facing the same problem. The version of JDK is jdk1.5.0_08.

Any suggestions/directions will be much appriciated.
Regards,
Shivaraj

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      01-11-2007
On 11 Jan 2007 07:39:48 -0800, shivaraj wrote:
> I am using "System.load("C:/sampleDLL2");" funtion to load a library.
>
> But getting
> Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:/sampleDLL2


[...]

> I tried using System.loadLibrary("sampleDLL2") method but here there
> also I am facing the same problem.



For System.loadLibrary() use the short name only, i.e. no path prefix
or dll extension, and make sure the file is in java.library.path or
your search PATH. For example:

System.loadLibrary("sampleDLL2");


For System.load(), specify the full path and filename. For example:

System.load("C:/sampleDLL2.dll");


System.loadLibrary() is the preferred mechanism.

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-11-2007
shivaraj wrote:
.....
> I am using "System.load("C:/sampleDLL2");"


It does not take you long to go wrong..

Never construct file paths the way you
did above, and when things are breaking,
*check* your *assumptions*.

<snippet>
File f = new File("C:");
System.out.println(f + " \t" + f.exists());
// get a /new/ file, using the
// path separator for this system.
f = new File(f, "sampleDLL2");
System.out.println(f + " \t" + f.exists());
System.load( f.toString() );
...
</snippet>

Andrew T.

 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      01-11-2007
Gordon Beaton wrote:
> For System.load(), specify the full path and filename. For example:
>
> System.load("C:/sampleDLL2.dll");

or better yet:
System.load("C:\\sampleDLL2.dll");
in oder to support older Windows platforms (which are less tolerant with
file separator slashes than current Windows XP).

--
Thomas
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-11-2007
Thomas Fritsch wrote:
> Gordon Beaton wrote:
> > For System.load(), specify the full path and filename. For example:
> >
> > System.load("C:/sampleDLL2.dll");

> or better yet:
> System.load("C:\\sampleDLL2.dll");


or best yet..
File theNative = new File(parent, "child");
System.load(theNative);

> in oder to support older Windows platforms (which are less tolerant with
> file separator slashes than current Windows XP).


...in order to support 'newer' Windows - when MS
suddenly decides to change the file separator they
use for their filesystem*.

* Though of course, they'd probably change the
'drive mapping' at the same time...

Andrew T.

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      01-11-2007
On 11 Jan 2007 08:33:24 -0800, Andrew Thompson wrote:
> or best yet..
> File theNative = new File(parent, "child");
> System.load(theNative);


No, System.loadLibrary() is better.

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-12-2007
Gordon Beaton wrote:
> On 11 Jan 2007 08:33:24 -0800, Andrew Thompson wrote:
> > or best yet..
> > File theNative = new File(parent, "child");
> > System.load(theNative);

>
> No, System.loadLibrary() is better.


OK good point. But I *was* concentrating on the
first, rather than the second line. So.. to be clearer.

When dealing with *files*,
//preferred
File file1 = new File(parentDir, "name.txt");
// rather than
File file 2 = new File("C:\\some\\long\\path\\name.txt");

Andrew T.

 
Reply With Quote
 
shivaraj
Guest
Posts: n/a
 
      01-16-2007
Hi All,
Thanks to all of you for your quick response. My problem got resolved.
System.loadLibrary did this trick for me. Thanks once again for helping
me out.
Regards,
Shivaraj

Andrew Thompson wrote:
> shivaraj wrote:
> ....
> > I am using "System.load("C:/sampleDLL2");"

>
> It does not take you long to go wrong..
>
> Never construct file paths the way you
> did above, and when things are breaking,
> *check* your *assumptions*.
>
> <snippet>
> File f = new File("C:");
> System.out.println(f + " \t" + f.exists());
> // get a /new/ file, using the
> // path separator for this system.
> f = new File(f, "sampleDLL2");
> System.out.println(f + " \t" + f.exists());
> System.load( f.toString() );
> ...
> </snippet>
>
> Andrew T.


 
Reply With Quote
 
antan_sw antan_sw is offline
Junior Member
Join Date: Nov 2009
Posts: 1
 
      11-09-2009
can anyone please tell me exactly in which folder i'll have to copy dll file to load it from System.loadlibrary

i already have done all jni stuffs. right now facing unsatisfiedlinkerror problem
 
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
JNI 64bit JVM, load 32bit native library mark.faine@gmail.com Java 4 06-22-2011 07:34 AM
Java Program can not load JNI Library adnan.iiui@gmail.com C++ 0 04-11-2011 05:34 AM
Re: JNI: Error loading DLL from JNI DDL vasanth Java 0 01-25-2005 11:01 AM
Porting JNI Windows under JNI LINUX + Wine ? Pasturel Jean-Louis Java 5 03-03-2004 07:50 PM
IBM's JNI fails where Sun's JNI works Alex Hunsley Java 4 11-04-2003 10:34 AM



Advertisments