5 messages in net.java.dev.jna.usersRe: [jna-users] problems with jna - c...
FromSent OnAttachments
Rui CaridadeOct 17, 2007 2:45 pm 
Timothy WallOct 17, 2007 4:12 pm 
Glick, Gene (GE Indust, Security)Oct 19, 2007 9:45 am 
Timothy WallOct 19, 2007 11:35 am 
Rui CaridadeOct 23, 2007 9:21 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] problems with jna - cdrom control libActions...
From:Timothy Wall (twal@dev.java.net)
Date:Oct 17, 2007 4:12:15 pm
List:net.java.dev.jna.users

On Oct 17, 2007, at 5:45 PM, Rui Caridade wrote:

// The test

NativeLibrary.addSearchPath("libjIso.so","/home/persefone/Esoteric/ jar/native/linux/");

iso9660Lib iso = (iso9660Lib)NativeLibrary.getInstance("libjIso.so");

You technically only need "jIso" as the library name, although on linux the full filename probably works as well.

You will, however, get a class cast exception when NativeLibrary finally returns a value. You need to use Native.loadLibrary(), which returns an instance of your interface bound to the native library, not NativeLibrary.getInstance(), which returns a NativeLibrary object.

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libjIso.so' at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:100) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:139) at test.main(test.java:14)

I'm running this from within eclipse.The jar is on the classpath but not on the same dir as the libs i'm calling can that be the reason.This is the first time i'm trying to use jna so please feel free to point my stupid mistakes..

JNA uses the path specified in jna.library.path to search for libraries, and falls back to the system path if that fails (in this case, LD_LIBRARY_PATH). Neither java.class.path nor java.library.path is used to look up user libraries.

Setting jna.library.path is usually preferable to hard-coding paths.

Since you're using eclipse, why don't you just put a breakpoint on the offending exception and examine the paths being tried? It might be something as simple as a typo in your path string.