Re: Why is jna.library.path needed on Linux?

426 views
Skip to first unread message

Stefan v. Wachter

unread,
Jul 19, 2011, 7:55:53 AM7/19/11
to Java Native Access
This code seems to solve the problem:

private static void initJnaLibPathLinux() {
String netbeansDirs = System.getProperty("netbeans.dirs");
String newJnaLibPath = "";
for(String path : netbeansDirs.split(":")) {
path = path + "/modules/lib";
if (newJnaLibPath.isEmpty() == false) {
newJnaLibPath = newJnaLibPath + ":";
}
newJnaLibPath = newJnaLibPath + path;
}
System.setProperty("jna.library.path", newJnaLibPath);
}


Stefan

Am 11.07.2011 09:58, schrieb Stefan v. Wachter:
> Hi all,
>
> I am porting a Netbeans application with use of JNA to Linux. My JNA
> version is 3.2.5 .
> On Windows I have the following code to load the dlls:
>
> // load dependent lib first
> System.loadLibrary("crypt");
> System.loadLibrary(bPNGClientLibName);
> optionMap = new HashMap();
> optionMap.put(Library.OPTION_FUNCTION_MAPPER, new
> StdCallFunctionMapper());
> theLib = (BpngClientLibrary)
> Native.loadLibrary(bPNGClientLibName, BpngClientLibrary.class,
> optionMap);
>
> On Linux it works only with a call to set the jna.library.path:
>
> initJnaLibPath("/home/wachter/src/BPNG/Client/
> NativeLibNbm/release/modules/lib");
> System.loadLibrary("crypt");
> // System.loadLibrary(bPNGClientLibName);
> theLib = (BpngClientLibrary)
> Native.loadLibrary(bPNGClientLibName, BpngClientLibrary.class);
>
> Without setting jna.library.path I get an
> "java.lang.UnsatisfiedLinkError: Unable to load library
> 'BPNGClientLib': libBPNGClientLib.so: Kann die Shared-Object-Datei
> nicht öffnen: Datei oder Verzeichnis nicht gefunden" error.
> I don't want to set jna.library.path because I do not know the path
> where the lib will reside on a customers computer. It is strange that
> calling System.loadLibrary(bPNGClientLibName); does not give an error!
> How can I get rid of setting the jna.library.path or how can I get the
> right value for it at runtime?
>
> Thanks for help!
> Stefan
>
>

Reply all
Reply to author
Forward
0 new messages