com.moesol.bindings
Class NativeLibraryFinder

java.lang.Object
  extended by com.moesol.bindings.NativeLibraryFinder

public class NativeLibraryFinder
extends Object


Field Summary
static String[] OS_PREFIXES
           
 
Constructor Summary
NativeLibraryFinder()
           
 
Method Summary
static File getLibraryDirectory()
           
static List getStrategies()
           
static void loadLibrary(Class classInJar, String libraryName)
          Finds and loads a native library using several different strategies.
static void setLibraryDirectory(File libraryDirectory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OS_PREFIXES

public static String[] OS_PREFIXES
Constructor Detail

NativeLibraryFinder

public NativeLibraryFinder()
Method Detail

loadLibrary

public static void loadLibrary(Class classInJar,
                               String libraryName)
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:
  1. tries System.loadLibrary
  2. 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.
  3. 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
  4. 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
 

Parameters:
classInJar - a class that is in the jar to be located
libraryName - name of library to load

getLibraryDirectory

public static File getLibraryDirectory()

setLibraryDirectory

public static void setLibraryDirectory(File libraryDirectory)

getStrategies

public static List getStrategies()


Copyright © 2004 Moebius Solutions, Inc. All Rights Reserved.