what otmcjni library java dll jar jni

java - otmcjni - Extraiga y cargue DLL de JAR



system load library (2)

try { InputStream in = Main.class.getResourceAsStream("/example-input.dll"); File fileOut = new File("./example-output.dll"); DataOutputStream writer = new DataOutputStream(new FileOutputStream(fileOut)); long oneChar = 0; while((oneChar = in.read()) != -1){ writer.write((int)oneChar); } in.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); }

Mi aplicación Java usa una biblioteca DLL. ¿Cómo puedo hacer que funcione desde el archivo JAR?

La DLL está en la carpeta de fuentes del proyecto. Tengo que incluirlo en mi JAR, extraerlo en tiempo de ejecución (en el mismo directorio del contenedor) y cargarlo.


Debe colocar dll en la ruta de su biblioteca ( recomendado ) antes de intentar cargarlo. para que tenga que extraerlo del jar y copiarlo en la ruta de lib.

private static void loadLib(String path, String name) { name = System.mapLibraryName(name); // extends name with .dll, .so or .dylib try { InputStream in = ACWrapper.class.getResourceAsStream("/"+path + name); File fileOut = new File("your lib path"); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); System.load(fileOut.toString());//loading goes here } catch (Exception e) { //handle } }

Nota: ACWrapper es la clase que contiene el método estático