Dependency libraries on Java JNI and windows

Long story short: I have an executable jar whose call depends on lib JNI. DLL dll. And I got such a bad unsatisfied linkerror

This answer is very close, but from my experience, it can't solve the problem Even in Java library. Path specifies the folder where the DLL is located. It will not work properly I must also change the windows path environment variable In fact, the default on windows is Java library. Path appears to be path

Is there any "beautiful" way to solve this problem? I want to build an installer for windows. I want to know how I will handle this problem so that end users don't have to do any manual work

Edit:

I implemented the following: the application comes with a folder called "native_libs", which has dynamic libraries of all supported architectures The structure is as follows:

/
+- native_libs/
   +- windows/
   |  +- x86/
   |  |  +- ...
   |  +- x64/
   |     +- ...
   |
   +- linux/
   |  +- x86/
   |  |  +- ...
   |  +- x64/
   |     +- ...
   |
   +- libs/
      +- ...

During runtime and application initialization, the correct JRE architecture and operating system are detected, and the correct library files are copied to LIBS / folder java. library. Path is also set at runtime using the common hack Finally, use the native initiator to set the path environment variable of windows

Is there room for improvement? Perhaps copying the DLL in the same directory as the jar file will negate the setting of Java library. Need for path and path variables? I need to investigate loading DLL with system Load(), which negates the need to copy the file

Solution

java. library. Path specifies system Loadlibrary() finds the directory of dynamic library files If you change Java. Net in your code library. The path system property has no effect Some hackers let Java "forget" the initial value and re evaluate Java library. The contents of the path system property

However, the dependency library is not loaded by Java, it is loaded by windows Windows doesn't care about Java library. Path, which only cares about the path environment variable Your only choice is to adjust the path of the java process For example, if you start it from a batch file, change the path environment variable before the Java call

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>