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

Discussion in 'Java' started by shivaraj, Jan 11, 2007.

  1. shivaraj

    shivaraj Guest

    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
     
    shivaraj, Jan 11, 2007
    #1
    1. Advertising

  2. 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
     
    Gordon Beaton, Jan 11, 2007
    #2
    1. Advertising

  3. 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.
     
    Andrew Thompson, Jan 11, 2007
    #3
  4. 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
     
    Thomas Fritsch, Jan 11, 2007
    #4
  5. 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.
     
    Andrew Thompson, Jan 11, 2007
    #5
  6. 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
     
    Gordon Beaton, Jan 11, 2007
    #6
  7. 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.
     
    Andrew Thompson, Jan 12, 2007
    #7
  8. shivaraj

    shivaraj Guest

    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.
     
    shivaraj, Jan 16, 2007
    #8
  9. shivaraj

    antan_sw

    Joined:
    Nov 9, 2009
    Messages:
    1
    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:
     
    antan_sw, Nov 9, 2009
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?q?J=F6rgen_Persson?=

    JNI java.lang.UnsatisfiedLinkError with found DLL

    =?iso-8859-1?q?J=F6rgen_Persson?=, Apr 11, 2006, in forum: Java
    Replies:
    5
    Views:
    24,079
    craned
    Aug 2, 2012
  2. TsanChung
    Replies:
    0
    Views:
    1,496
    TsanChung
    Sep 4, 2008
  3. gopinath511
    Replies:
    0
    Views:
    775
    gopinath511
    Jan 7, 2009
  4. gopinath511
    Replies:
    0
    Views:
    1,479
    gopinath511
    Jan 7, 2009
  5. Replies:
    5
    Views:
    1,469
    Roedy Green
    Jun 18, 2012
Loading...

Share This Page