loading dependent 3rd party libraries [ Can't find dependent libraries ]

216 views
Skip to first unread message

mschoudry

unread,
Apr 14, 2017, 7:50:55 AM4/14/17
to NAR Maven plugin
Hi,
I am using maven-nar-plugin along with native-lib-loader to load the native library.
To illustrate the concept a bit more, i have three maven projects

A [Native Project] => produces nar (This nar contains 3rd party dll)
c++[uses 3rd party dll]
java wrapper

B [Java Project] => produces jar
uses A

C [Client Application Project] => produces executable
uses B

All projects compile successfully.
When i try to execute application project C, the A.dll is loaded but is unable to load the 3rd Party dll.

An exception is thrown stating:

java.lang.UnsatisfiedLinkError native-*.dll Can't find dependent libraries


Is it possible to load 3rd party libraries, along with native library?

Any suggestions?

Thanks in advance

Regards,

Curtis Rueden

unread,
Apr 17, 2017, 2:08:02 PM4/17/17
to mschoudry, NAR Maven plugin
Hi,

> An exception is thrown stating:
> java.lang.UnsatisfiedLinkError native-*.dll Can't find dependent
> libraries

Looking at the source of native-lib-loader, it appears to always use System.load:

  $ git grep '^[^\*]*System.load'
  src/main/java/org/scijava/nativelib/NativeLibraryUtil.java:                             System.load(extractedFile.getPath());
  src/main/java/org/scijava/nativelib/NativeLoader.java:          System.load(jniExtractor.extractJni("", libname).getAbsolutePath());

System.load is the low-level, you-need-to-manually-load-your-dependencies-in-bottom-up-order solution. The high-level solution, System.loadLibrary, loads dependencies recursively, but requires the java.library.path variable to be set properly before the JVM starts up. So AFAIK, there is no perfect solution here.

It would be awesome to have a more universal, turn-key solution for interfacing Java code with native code in a way that manages dependencies really properly. Unfortunately, NAR and native-lib-loader do not take things all the way, and doing so would require a substantial time investment, IMHO, along with expert understanding of both technologies (Java and native libraries).

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden



--
You received this message because you are subscribed to the Google Groups "NAR Maven plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maven-nar+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

saqib...@gmail.com

unread,
Apr 18, 2017, 4:13:08 AM4/18/17
to NAR Maven plugin, saqib...@gmail.com, ctru...@wisc.edu
Hi Curtis,
Thanks for a detailed reply.
I agree with you, there isn't any good solution for such problem, as at Java level, it is difficult to find out all the dependent libraries of Native library.
I was trying to find out some solution where Project A would be able to load all of its dependencies itself, without bothering Project C(Client application project) to do this job, but not successful so far.

The best solution so far seems to be, as also suggested by you, is to pass the directory of dependent libraries as java.library.path.

Regards,
Saqib
> To unsubscribe from this group and stop receiving emails from it, send an email to maven-nar+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages