Tess4j : java.lang.UnsatisfiedLinkError: Unable to load library

HelloWorld0815 picture HelloWorld0815 · Sep 14, 2014 · Viewed 12.7k times · Source

Im using tess4j.jar in my Eclipse project. When i run it on eclipse my project is working fine, but when i try to run the exported runnable .jar file it always fails due to "java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302'" error.

I tried to fix it with solutions from similar posts but nothing worked.

  1. Located the 'libtesseract302' and 'liblept168.dll' file into a "dll" folder an added it as source folder.
  2. I´m running java 32bit and confirmed that the dlls are also 32bit dlls.

Error log:

Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302': Can't obtain InputStream for win32-x86/libtesseract302.dll
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
    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.TessAPI.<clinit>(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.init(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at brain.Main.startOCR(Main.java:292)
    at brain.Main.getOcrResult(Main.java:251)

Answer

nguyenq picture nguyenq · Sep 15, 2014

If the DLLs are packaged in the JAR file, they will need to be extracted. Then set jna.library.path system property to the location of the DLL files (see Tutorial).