简体   繁体   中英

Tess4J InvocationTargetException

I have a problem running the below java code outside of the eclipse compiler. Inside the compiler it works fine, but after exporting as a runnable jar I get an InvocationTargetException. I believe it is relevant to the dll files but after reading other solutions here and tryinging to implement them the problem remained unresolved. So my question is it possible to configure eclipse, through code or settings, to export the program correctly?

Relevant Code

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

Maven Dependencies are 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 "";
    }

Error

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 . . .

In case anyone has a similar issue what I did was copy the 3 .dll files into my System32 folder. I then got an issue with image.io, which the site had plenty of answers for. My personal solution was exporting the jar as my code and a separate folder for the libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM