【问题标题】:Tess4j Issue in Windows: java.lang.UnsatisfiedLinkError: The specified module could not be found in instance.doOCR(imageFile)Windows 中的 Tess4j 问题:java.lang.UnsatisfiedLinkError:在 instance.doOCR(imageFile) 中找不到指定的模块
【发布时间】:2016-01-06 17:07:18
【问题描述】:

经过 2 天的谷歌搜索,我仍然无法找到 Tess4j 3.0 版问题的解决方案:java.lang.UnsatisfiedLinkError: The specified module could not be found.

我在 Windows 10 x64 上编写服务器端 Spring Boot 应用程序。我用了这个教程http://tess4j.sourceforge.net/tutorial/ 我在 tess4j 项目的源代码中创建了ant test,这个命令在我的 PC 上运行正常。我还安装了适用于 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

感谢您的帮助!

【问题讨论】:

  • 您缺少一个依赖库。确保所有依赖库都在 PATH 上或与 JNA 加载的库位于同一目录中。您可以使用depends.exe 来确定完整的依赖集。
  • @technomage,是的,我知道丢失的库,但是我怎样才能快速解决所有这些问题,顺便说一句,我已经安装了适用于 VS2012 的 Visual C++ Redistributable 和适用于 VS2013 的 Visual C++ Redistributable。跨度>
  • 您可以使用 -Djna.debug_load 让 JNA 将它正在搜索我们的主 DLL 的所有位置以及最终加载的位置打印到控制台。

标签: java tesseract jna tess4j


【解决方案1】:

我认为你被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 运行时(再次提醒:不要被误导:12.0 是 2013,这可能会让人很困惑)

据推测 liblept171.dll 是丢失的东西,因此您应该检查它的存储位置以及为什么一个项目能够找到它而不是另一个项目。一个好主意是将所有依赖项复制到一个公共路径中并将 java.library.path 设置为该目录(仅用于测试目的)

liblept171.dlllept4j 的一部分,在您的 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 运行时和 Tesseract 的位数是否匹配。如果有疑问:安装 x86 和 x64。

作为进一步的故障排除帮助,您可能希望找出正在搜索 dll 的位置。将procmon.exe 与该dll 的过滤器一起使用。

【讨论】:

    【解决方案2】:

    此问题与 Windows 10 无关。

    我已经通过添加修复了错误

    <dependency>
        <groupId>net.sourceforge.tess4j</groupId>
        <artifactId>tess4j</artifactId>
        <version>3.0.0</version>
    </dependency>
    

    而不是所有以前的 maven 依赖项。

    【讨论】:

      猜你喜欢
      • 2017-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多