private static void loadLibraryResource ( String resourceSubdirectoryName , String libraryName , String tempSubdirectoryName , String ... dependentLibraryNames ) throws Throwable { // First try to load all dependent libraries, recursively for ( String dependentLibraryName : dependentLibraryNames ) { logger . log ( level , "Library " + libraryName + " depends on " + dependentLibraryName ) ; String dependentResourceSubdirectoryName = resourceSubdirectoryName + "/" + osString ( ) + "/" + archString ( ) ; String dependentLibraryTempSubDirectoryName = libraryName + "_dependents" + File . separator + osString ( ) + File . separator + archString ( ) + File . separator ; loadLibraryResource ( dependentResourceSubdirectoryName , dependentLibraryName , dependentLibraryTempSubDirectoryName ) ; } // Now, prepare loading the actual library String libraryFileName = createLibraryFileName ( libraryName ) ; File libraryTempFile = createTempFile ( tempSubdirectoryName , libraryFileName ) ; // If the temporary file for the library does not exist, create it if ( ! libraryTempFile . exists ( ) ) { String libraryResourceName = resourceSubdirectoryName + "/" + libraryFileName ; logger . log ( level , "Writing resource " + libraryResourceName ) ; logger . log ( level , "to temporary file " + libraryTempFile ) ; writeResourceToFile ( libraryResourceName , libraryTempFile ) ; } // Finally, try to load the library from the temporary file logger . log ( level , "Loading library " + libraryTempFile ) ; System . load ( libraryTempFile . toString ( ) ) ; logger . log ( level , "Loading library " + libraryTempFile + " DONE" ) ; }
Load the library with the given name from a resource .