经过2天的谷歌搜索后,我仍无法找到Tess4j 3.0版的问题解决方案:java.lang.UnsatisfiedLinkError:找不到指定的模块。
我在Windows 10 x64上编写服务器端Spring启动应用程序。我使用了这个教程http://tess4j.sourceforge.net/tutorial/
我在tess4j项目的源代码中创建了ant test
,这个命令在我的电脑上运行正常。我还安装了VS2012的Visual C ++ Redistributable和VS2013的Visual C ++ Redistributable。
但我错过了我的电脑中的dll,libtesseract304.dll取决于:
这可能是问题的原因吗?但是Tess4J-3.0-src项目在我的电脑上运行良好怎么可能呢?
我的完整堆栈跟踪:
java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:263) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Library$Handler.<init>(Library.java:147) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:502) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:481) ~[jna.jar:4.2.1 (b0)]
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.init(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at ocr.OCRController.handleFileUpload(OCRController.java:109) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
我的代码:
ITesseract instance = new Tesseract(); // JNA Interface Mapping
instance.setDatapath(new File(datapath).getPath());
instance.setLanguage("eng");
try {
String result = instance.doOCR(imageFile); //error here
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
行家:
<dependency>
<groupId>jai_imageio</groupId>
<artifactId>com.jai_imageio</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jai_imageio.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-io-2.4</groupId>
<artifactId>com.commons-io-2.4</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-io-2.4.jar</systemPath>
</dependency>
<dependency>
<groupId>jna</groupId>
<artifactId>com.jna</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jna.jar</systemPath>
</dependency>
<dependency>
<groupId>tess4j-3.0</groupId>
<artifactId>com.tess4j-3.0</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/tess4j-3.0.jar</systemPath>
</dependency>
我还尝试以强制方式加载库:
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/gsdll64");
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/libtesseract304");
但没有成功:
There was an unexpected error (type=Internal Server Error, status=500).
C:\Users\Iuliia\IdeaProjects\ENumbersBackend\lib\win32-x86-64\libtesseract304.dll: Can't find dependent libraries
感谢您的帮助!
答案 0 :(得分:2)
我认为你们被depends.exe的输出误导了。
DLL只导入其他dll:
dumpbin libtesseract304.dll /imports|find ".dll"
Dump of file libtesseract304.dll
WS2_32.dll
liblept171.dll
MSVCP120.dll
MSVCR120.dll
KERNEL32.dll
要进行双重检查,您可以获得用于编译该DLL的链接器版本:
dumpbin libtesseract304.dll /headers | find "linker version"
12.00 linker version
所以你需要的只是Visual Studio 2013 Runtime(再次:不要被误导:12.0是2013年,这可能相当混乱)
据推测,liblept171.dll是缺少的东西,所以你应该检查它存储的位置以及为什么一个项目能够找到它而不是另一个。一个好主意是将所有依赖项复制到一个公共路径并将java.library.path设置为该目录(仅用于测试目的)
liblept171.dll
是lept4j的一部分,在你的lib目录中有一个相应名称的.jar,其中包含该dll:
7z l lib\lept4j-1.0.1.jar | find ".dll"
2015-11-14 11:46:04 ..... 2406400 2406400 win32-x86-64\liblept171.dll
2015-11-14 11:46:04 ..... 1834496 1834496 win32-x86\liblept171.dll
此外,您应该注意JRE,Visual Studio Runtime和Tesseract的位数是否匹配。如有疑问:安装x86和x64。
作为进一步的故障排除帮助,您可能想要找出搜索dll的位置。使用procmon.exe
和该dll的过滤器。
答案 1 :(得分:0)
该问题与Windows 10无关。
我已经通过添加
修复了错误<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.0.0</version>
</dependency>
而不是所有以前的maven依赖项。