【问题标题】:Tess4J InvocationTargetExceptionTess4J 调用目标异常
【发布时间】:2015-12-13 20:30:15
【问题描述】:

我在 Eclipse 编译器之外运行以下 java 代码时遇到问题。在编译器内部它工作正常,但在导出为可运行的 jar 后,我得到一个 InvocationTargetException。我相信它与 dll 文件有关,但是在阅读了此处的其他解决方案并尝试实施它们之后,问题仍未解决。所以我的问题是可以通过代码或设置配置eclipse来正确导出程序吗?

相关代码

BTW C:\Program Files\Tesseract-OCR 包含 tessdata、gsdll64.dll、liblept170.dll、libtesseract303.dll

Maven 依赖有 tess4j、junit、ghost4j

public Bot() {
        System.setProperty("jna.library.path", "C:/Program Files/Tesseract-OCR");
        ocr2 =  new Tesseract();
        ocr2.setDatapath("C:/Program Files/Tesseract-OCR");
        initLists();
        System.out.println(scan(0,0,500,500));
    }
public String scan(int x, int y, int x2, int y2) {
        BufferedImage i = rob.getScreen(x, y, x2, y2);
        i = toBufferedImage(i.getScaledInstance(i.getWidth()*2, i.getHeight() *2, Image.SCALE_SMOOTH));
        try {
            return ocr2.doOCR(i).trim();
        } catch (TesseractException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

错误

C:\Users\Blue\Desktop>java -jar bot.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: The specified module could not be found.

        at com.sun.jna.Native.open(Native Method)
        at com.sun.jna.Native.open(Native.java:1759)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
        at com.sun.jna.Library$Handler.<init>(Library.java:147)
        at com.sun.jna.Native.loadLibrary(Native.java:412)
        at com.sun.jna.Native.loadLibrary(Native.java:391)
        at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:78)
        at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:40)
        at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:360)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:273)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:256)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:237)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:221)
        at debug.Bot.scan(Bot.java:480)
        at debug.Bot.<init>(Bot.java:53)
        at debug.Bot.main(Bot.java:24)
        ... 5 more

C:\Users\Blue\Desktop>pause
Press any key to continue . . .

【问题讨论】:

  • 您是否确认 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader 存在于您打包的 JAR 文件中?如果它不存在,那么也许您可以尝试这里的建议:stackoverflow.com/a/27283043/1990536
  • 谢谢,我设法找到了一个有效的修复程序。

标签: java eclipse maven tesseract tess4j


【解决方案1】:

如果有人遇到类似问题,我所做的就是将 3 个 .dll 文件复制到我的 System32 文件夹中。然后我遇到了 image.io 的问题,该网站有很多答案。我个人的解决方案是将 jar 导出为我的代码和一个单独的库文件夹。

【讨论】:

  • 您不需要设置jna.library.path 变量或触摸 DLL,除非您想加载自己的自定义库。
猜你喜欢
  • 1970-01-01
  • 2018-07-02
  • 2013-11-29
  • 1970-01-01
  • 1970-01-01
  • 2022-12-15
  • 2023-02-22
  • 2019-01-22
  • 1970-01-01
相关资源
最近更新 更多