Tess4J InvocationTargetException

时间:2015-12-13 20:30:15

标签: java eclipse maven tesseract tess4j

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

相关代码

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

Maven Dependencies是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 . . .

1 个答案:

答案 0 :(得分:0)

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