The production environment our Java Web Application is deployed in has several permission restrictions, one of them being unable to write in drive C:
We recently added jna-4.1.0.jar and jna-platform-4.1-0.jar dependencies to be able to read Windows Registry but I've noticed that every time server (Tomcat v7.0) is started a DLL file is extracted to a Tomcat temporary folder, giving the following error:
java.lang.UnsatisfiedLinkError: C:\Program Files\Apache Software Foundation\Tomcat 7.0\temp\jna-1319675979\jna1892288885647543043.dll: The handle is invalid
I've verified that this same DLL is extracted successfully when access permission restriction is removed to ensure this is the source of my problem, but I want to know if there is any way to specify a custom path where that DLL must be extracted to, since we are able to write in drive E:, for example.
The DLL you're seeing is JNA's JNI library used to dispatch native calls [0]. JNA will extract the library to a temporary folder, unless found from the directory specified by the jna.boot.library.path
property [1], or with System.loadLibrary
[2].
The directory used for temporary items can be set with the jna.tmpdir
property [3]. For example:
java -jar program.jar -Djna.tmpdir=E:/temp
If jna.tmpdir
is not set, JNA will use java.io.tmpdir
.
Notice that at the time of writing, JNA will use File.mkdirs()
to create the directory structure of the tmpdir
, so you don't need to make sure the folders exist.