java - How to get JNA to extract several DLL files from a jar file? -


i working on java project in netbeans using jna. according jna documentation, can make dll:s available java putting in jar:

make native library available on classpath, under path {os}-{arch}/{library}, {os}-{arch} jna's canonical prefix native libraries (e.g. win32-x86, linux-amd64, or darwin). if resource within jar file automatically extracted when loaded.

this want do, have included dll:s in project under src/win32-x86-64. if build jar-file netbeans, , include jar file in project works fine , jna finds library without problem. jna.debug_load on:

looking in classpath sun.misc.launcher$appclassloader@15db9742 /com/sun/jna/win32-x86-64/jnidispatch.dll found library resource @ jar:file:/c:/mynetbeansproject/dist/lib/jna-4.2.2.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll looking library 'mylibrary' adding paths jna.library.path: null trying mylibrary.dll adding system paths: [] trying mylibrary.dll looking lib- prefix trying libmylibrary.dll looking in classpath sun.misc.launcher$appclassloader@15db9742 mylibrary found library resource @ file:/c:/mynetbeansproject/build/classes/win32-x86-64/mylibrary.dll looking in c:/mynetbeansproject/build\classes\win32-x86-64\mylibrary.dll found library 'mylibrary' @ c:/mynetbeansproject/build\classes\win32-x86-64\mylibrary.dll 

apparently dll jar not used. instead dll build folder used.

now, if move jar-file folder , include in project, unsatisfiedlinkerror. jna gives following output:

looking in classpath sun.misc.launcher$appclassloader@70dea4e /com/sun/jna/win32-x86-64/jnidispatch.dll found library resource @ jar:file:/c:/somefolder/lib/jna-4.2.2.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll looking library 'mylibrary' adding paths jna.library.path: null trying mylibrary.dll adding system paths: [] trying mylibrary.dll looking lib- prefix trying libmylibrary.dll looking in classpath sun.misc.launcher$appclassloader@70dea4e mylibrary found library resource @ jar:file:/c:/somefolder/mynetbeansproject.jar!/win32-x86-64/mylibrary.dll 

it looks jna finds dll in jar, not try extract it. can not find in temp folder (where jna extracts it's own internal dll).

what problem here? why doesn't jna extract file? how can fix this?

(i don't know if relevant, should mention dll depends on multiple other dll files in same folder in jar. not sure if jna extract them automatically me, far seems jna isn't extracting dll using.)

edit: there seems no problem locating jnidispatch.dll. according output when jna.debug_load.jna set true file found in jar , extracted temp folder.

jna show error "unsatisfiedlinkerror" when dll couldn't loaded. if dll needs custom dlls not present in system path fail, jna doesn't extract dll automatically.

jna java library doesn't know dependencies of system library, can't extract jar. the solution specify dependencies in jna java interfaces.

you can see example here load multiple dependent libraries jna


what happening behind scenes of operating system

at end, libraries loaded operating system requested main executable. in case main executable java.exe or (jvm.dll). if system can't find library in path fails , java generates exception.

another related , solved question registering multiple .dll libraries single java class using jna


Comments