diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java index c6fd50fb8a230d9067040dfdcbac4548ca482ca7..b3583c537f9caf1409b7b729dd179d78559a373c 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java @@ -944,6 +944,36 @@ public final class FileUtilities OSUtilities.getComputerPlatform(), libraryName), libraryName, ".so"); } + /** + * Loads the native library <var>libraryName</var> from a Java resource that follows tha naming + * convention described in {@link #tryCopyNativeLibraryToTempFile(String)}. + * + * @return <code>true</code> if the library has been loaded successfully and + * <code>false</code> otherwise. + */ + public final static boolean loadNativeLibraryFromResource(final String libraryName) + { + final String filename = FileUtilities.tryCopyNativeLibraryToTempFile(libraryName); + + if (filename != null) + { + final File linkLib = new File(filename); + if (linkLib.exists() && linkLib.canRead() && linkLib.isFile()) + { + try + { + System.load(filename); + return true; + } catch (final Throwable err) + { + System.err.printf("Native library '%s' failed to load:\n", filename); + err.printStackTrace(); + } + } + } + return false; + } + /** * Tries to copy the resource with the given name to a temporary file. *