org.scijava.nativelib
Class NativeLibraryUtil

java.lang.Object
  extended by org.scijava.nativelib.NativeLibraryUtil

public class NativeLibraryUtil
extends Object

This class is a utility for loading native libraries.

Native libraries should be packaged into a single jar file, with the following directory & file structure:

META_INF lib linux_32 libxxx[-vvv].so linux_64 libxxx[-vvv].so osx_32 libxxx[-vvv].dylib osx_64 libxxx[-vvv].dylib windows_32 xxx[-vvv].dll windows_64 xxx[-vvv].dll

Here "xxx" is the name of the native library and "-vvv" is an optional version number.

Current approach is to unpack the native library into a temporary file and load from there.

Author:
Aivar Grislis

Nested Class Summary
static class NativeLibraryUtil.Architecture
           
 
Constructor Summary
NativeLibraryUtil()
           
 
Method Summary
static NativeLibraryUtil.Architecture getArchitecture()
          Determines the underlying hardware platform and architecture.
static String getPlatformLibraryName(String libName)
          Returns the full file name (without path) of the native library.
static String getPlatformLibraryPath()
          Returns the path to the native library.
static String getVersionedLibraryName(Class libraryJarClass, String libName)
          Returns the Maven-versioned file name of the native library.
static boolean loadNativeLibrary(Class libraryJarClass, String libName)
          Loads the native library.
static boolean loadVersionedNativeLibrary(Class libraryJarClass, String libName)
          Loads the native library.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NativeLibraryUtil

public NativeLibraryUtil()
Method Detail

getArchitecture

public static NativeLibraryUtil.Architecture getArchitecture()
Determines the underlying hardware platform and architecture.

Returns:
enumerated architecture value

getPlatformLibraryPath

public static String getPlatformLibraryPath()
Returns the path to the native library.

Returns:
path

getPlatformLibraryName

public static String getPlatformLibraryName(String libName)
Returns the full file name (without path) of the native library.

Parameters:
libName -
Returns:
file name

getVersionedLibraryName

public static String getVersionedLibraryName(Class libraryJarClass,
                                             String libName)
Returns the Maven-versioned file name of the native library. In order for this to work Maven needs to save its version number in the jar manifest. The version of the library-containing jar and the version encoded in the native library names should agree. maven-jar-plugin true * com.example.package true * * = necessary to save version information in manifest

Parameters:
libName -
Returns:

loadVersionedNativeLibrary

public static boolean loadVersionedNativeLibrary(Class libraryJarClass,
                                                 String libName)
Loads the native library. Picks up the version number to specify from the library-containing jar.

Parameters:
libraryJarClass - any class within the library-containing jar
libName - name of library
Returns:
whether or not successful

loadNativeLibrary

public static boolean loadNativeLibrary(Class libraryJarClass,
                                        String libName)
Loads the native library.

Parameters:
libraryJarClass - any class within the library-containing jar
libName - name of library
Returns:
whether or not successful


Copyright © 2010–2014 SciJava. All rights reserved.