Copy the OS dependent library from the resources dir in a JAR to a temporary location and optionally ask the JVM to load the library.
Copy the OS dependent library from the resources dir in a JAR to a temporary location and optionally ask the JVM to load the library. The library is deleted on exit from the JVM. If load is false, it just copies the library to the temporary location without loading it.
The name of the library to copy and optionally load
If true, ask the JVM to dynamically load the library using System.load()
General loader for dynamic libraries from the resources directory in the jar file. It copies the required library from the jar to the target temporary directory and then optionally loads the file using System.load(). It will clean the directory on JVM shutdown using shutdown hooks. It is clever enough to find the correct directory for the native version of the library (although this is untested). Note that you need to build the JNI native stubs with some care so that dependent libraries can be loaded. In Linux for example, Java must load libjni_opus.so (JNI native code). The actual Opus library is loaded by the dynamic linker from a dependency in the stub. Libjni_opus.so is built to look in the same directory for libopus, so we must copy it to a temporary directory as well, but there is no need to ask the JVM to load it. In Windows, you will need to load it as well.
Libraries are stored in the resources/native/os.name/os.arch directory and copied to the system temporary directory as indicated by the java.io.tmpdir property plus a random one time directory name with the prefix "scopus_". In Linux, the temporary directory would have a name like "/tmp/scopus_418af7c0b63b/".