Finds and loads a native library using several different
strategies. The default set of strategies tries to
find the native library using the following search:
- tries System.loadLibrary
- tries to find the library in the same directory as the jar.
If the URL to the jar is not the
file:
protocol this step is skipped.
- tries to find a library with the same name as the
jar file with the .jar extension removed.
This supports maven since maven will rename artifacts so
that the name of the jar file and native library will
include the version number. For example, on Windows a jar
file of
fobs4jmf-0.4.jar
will cause a search
for fobs4jmf-0.4.dll
- tries to find the library as a resource.
If found as a resource the native library is extracted to the
library directory property and loaded from there.
For both the file and resource searches it also searchs
for derivations based on the os, cpu architecture, and os version.
So on Windows a loadLibrary("foo")
looks for
{jar or classes directory}\foo.dll
{jar or classes directory}\Windows XP\x86\foo.dll
{jar or classes directory}\Windows XP\x86\5.1\foo.dll
{resource}/foo.dll
{resource}/Windows XP/x86/foo.dll
{resource}/Windows XP/x86/5.1/foo.dll
try {
System.loadLibrary(libraryName);
} catch (UnsatisfiedLinkError e) {
for (Iterator it = s_stategies.iterator(); it.hasNext(); ) {
NativeLibraryFinderStrategy s = (NativeLibraryFinderStrategy)it.next();
try {
s.findAndLoad(classInJar, libraryName);
return; // worked
} catch (UnsatisfiedLinkError e1) {
s_logger.log(Level.FINE, "strategy failed: " + s, e1);
}
}
throw e; // Throw the original System error for consistency
}