Why is tessdata throwing Exceptions?

2020-04-20 17:14发布

问题:

All is happening on MAC in SpringBoot WAR file deployed in Tomcat:

I have tesseract 4.1.0 installed (via brew on Mac).

For Tessdata - OCR on Mac

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

I also updated SpringBoot today to:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Now, when I try to run the OCR logic in tessdata (Service method in SpringBoot), I am first getting this error (on the mac):

java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;)Lcom/sun/jna/Library;

Then, if I try to OCR the Spanish png file again, I get this result:

"Could not initialize class net.sourceforge.tess4j.TessAPI"

The Tessdata code where the crash occurs seems to be:

public String doOCR(BufferedImage var1) throws TesseractException {
    return this.doOCR((BufferedImage)var1, (Rectangle)null);

I've seen postings here about this problem, but all the ones I've seen are for Windows. I also tried to load the dependency for jna just in case, but that made no difference.

Has anyone faced and fixed this issue?

The problem appears to be with the tess4j 4.4.0. If I back it out to the last version, then things work again.

Would really appreciate some ideas.

回答1:

It seems your application is loading an old JNA version. com.sun.jna.Native.load is new in JNA 5.x.x. So make sure you use the latest JNA version.

https://groups.google.com/forum/#!topic/jna-users/VKbCGUcotkg