2

我在 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 . . .
4

1 回答 1

0

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

于 2015-12-16T02:13:41.903 回答