Search code examples
javatomcatocrtesseractnative-code

Using Tess4J on Tomcat


When I use the Tess4J library I get an error:

java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.TessAPI

at runtime.

But I don't get the meaning of this error, nor I am able to resolve it.

My problem is that 2 native dlls have to be loaded by Tess4J but this is out of my hands. I've added the location of the dlls to the build path for each jar.

I noticed, that when I first trigger Tess4J with my client, I get an error:

java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302'

but every consecutive call results in the NoClassDefFoundErrorexception.


Solution

  • In my case switching from 64-bit Java to 32-bit Java solved the java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302' problem (Tesseract is a 32-bit app). Don't forget to put libtesseract302.dll, liblept168.dll and tessdata in jdk/bin folder.