java - UnsatisfiedLinkError when running JAR from outside directory -
i have javafx application deploy jar. application loads , uses native library (a jni interface).
the dll expected in same directory jar. how load library. have verified path correct dll.
string jarpath = classloader.getsystemclassloader().getresource(".").getpath(); system.out.println(jarpath); system.load(jarpath + "_jni.dll");
here issue: when execute java run jar same directory jar, works fine. when execute java run jar outside directory, throws:
java.lang.unsatisfiedlinkerror: c:/test/_jni.dll: %1 not valid win32 application @ java.lang.classloader$nativelibrary.load(native method)
for example:
::this works. dll loads , executes successfully. cd c:/test java -jar pdwin.jar ::this not work. unsatisifedlinkerror java -jar "c:/test/pdwin.jar"
my thoughts there bitness differences in components, or jni method signatures wrong, not true, have verified jvm 64 bit, , dll 64 bit.
the fact dll works fine when run java inside directory containing jar, doesn't work when run outside strange... (note: print path 'jarpath' , same correct path in both cases)
the problem is: windows automatically searches dlls in system directories , current working directory. in first example working directory set correctly in second not.
there multiple solutions this: creating start script allways changes working directory simplest.
my prefered solution be: put dll inside jar. use classloader open dll inputstream, copy in tempfile , load tempfile absolute system path. (see here: extract , load dll jar)
this solution can adapted work on different platforms.
Comments
Post a Comment