加载dtwainjni32.dll时遇UnsatisfiedLinkError:找不到依赖库
When loading the DTWAIN JNI library in Java, the "Can't find dependent libraries" error usually means the main DLL (dtwainjni32.dll) relies on other libraries that aren't accessible to the JVM. Here are practical steps to resolve this:
1. Identify Missing Dependencies
First, pinpoint exactly which libraries are missing using one of these tools:
- Dependency Walker: Open
dtwainjni32.dllwith this tool—any missing dependencies will show up with red icons. - Visual Studio's
dumpbin: Run this command in a VS command prompt to list all required DLLs:
Note down any DLLs that aren't present on your system or in a reachable path.dumpbin /dependents "C:\Program Files (x86)\Java\jdk1.8.0_361\bin\dtwainjni32.dll"
2. Match Architecture (32-bit vs 64-bit)
You're using a 32-bit JDK, so every DLL involved (DTWAIN library, its dependencies, scanner drivers) must be 32-bit. 64-bit DLLs won't load in a 32-bit JVM.
- To verify a DLL's architecture, run:
Look for "machine (x86)" to confirm it's 32-bit.dumpbin /headers <path-to-dll> | findstr "machine"
3. Make Dependencies Accessible
Once you have the missing DLLs, get them from the DTWAIN library package or your system, then:
- Place them in the same folder as
dtwainjni32.dll(your JDK'sbindirectory), or - Add their directory to the system
PATH(restart your terminal/IDE after modifying this), or - Specify the path when launching your Java app:
java -Djava.library.path="C:\path\to\dtwain-dlls;C:\path\to\other-dependencies" Main
4. Install Scanner Drivers and TWAIN Components
The DTWAIN library needs TWAIN/WIA support to communicate with scanners:
- Install the latest 32-bit TWAIN/WIA drivers for your scanner.
- Ensure
twain_32.dllexists inC:\Windows\SysWOW64(for 64-bit Windows running 32-bit apps) orC:\Windows\System32(for 32-bit Windows).
5. Double-Check Library Loading
- Confirm you're loading the correct DLL:
System.loadLibrary("dtwainjni32u")looks fordtwainjni32u.dll. If your file is nameddtwainjni32.dll, either rename it or adjust the load call toSystem.loadLibrary("dtwainjni32"). - Avoid using debug builds of the DLL—stick to release versions compatible with JDK 1.8.
6. Verify Required Environment Variables
Some DTWAIN setups need environment variables like DTWAIN_DIR pointing to the library's resource folder. Refer to the library's documentation for any such requirements and set them in your system or runtime environment.
内容的提问来源于stack exchange,提问作者Ariel

