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

S

shivaraj

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.<clinit>
(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
 
G

Gordon Beaton

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
 
A

Andrew Thompson

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.
 
T

Thomas Fritsch

Gordon said:
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).
 
A

Andrew Thompson

Thomas said:
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.
 
A

Andrew Thompson

Gordon said:
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.
 
S

shivaraj

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
 
Joined
Nov 9, 2009
Messages
1
Reaction score
0
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:damnmate:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top