JNA technology is used because work requires calling DLL, in the SDK provided by a third party. The development steps and the use of JNA have been familiar, and the development task has been completed, but there has always been a question: where on earth should the storage path of the DLL file in IDEA be placed?
< H1 > 2. Try < / H1 >first of all, let"s introduce the catalogue of the project:
:IDEA JDK 1.8 32bit
: ---
--- ...
--- lib Modules Dependencies lib
--- src Sources
--- ...
the DLL provided by the third party is 32bit, and finally successfully calls the third party"s DLL to implement the requirements, so the problem of bit incompatibility is eliminated.
-
lib directory of the project:
Caused by: java.lang.UnsatisfiedLinkError: Unable to load library "dllName": Native library (win32-x86/dllName.dll) not found in resource path ([file:/C:/Program%20Files%20(x86)/Java/jdk1.8.0_171/jre/lib/charsets.jar, ......
as above, there are two paths in the error report. I have tried to prevent the DLL file from being in the corresponding directory, but the error report is still the same
. - the src directory of the project:
is placed in the src directory. After testing, the DLL file can be loaded normally. Because of the directory structure of the project, it is definitely not possible to put it in the src directory. Ideally, it should be placed in the lib directory .
- in the C:Program Files (x86) Javajdk1.8.0_171jrebin directory:
in this directory is also the where DLL files can be loaded normally.
- in the C:WindowsSystem32 directory:
SDK development documentation says you can try to put DLL files in that directory, but testing on IDEA is not valid. - modify the VM option in the IDEA running configuration to:-Djava.library.path=D:\ *\ lib
this method is of no use either
- use absolute path
using absolute path does not load the DLL file correctly, and the absolute path does not meet the requirements
how to set the path to the DLL file in IDEA (in addition to the src directory), and in the IDE environment, how to ensure that the program loads the DLL file correctly at run time?