nguyenq / tess4j

Java JNA wrapper for Tesseract OCR API
Apache License 2.0
1.58k stars 372 forks source link

tomcat 9 war file with tess4j is giving java.lang.UnsatisfiedLinkError #223

Closed sanjeebsarkar closed 2 years ago

sanjeebsarkar commented 2 years ago

Hi , First of all, thank you so much for building this to help with OCR related work in Windows. Although there is a small problem when I am running this is in Windows 7 64bit, here are the VC++ redist packages I have installed :

image

The thing is , this program is working fine with eclipse-tomcat. In eclipse , there is Temp folder also getting created in the C:\ partition. And the TESSDATA_PREFIX path is also set to tesseract 5.0.0 installation location's tessdata folder.

After creating a war file and pasting it in tomcat 9 / webapps folder , and then running the startup.bat file. The tomcat 9 turns on perfectly , even the tess4j folder is also getting created in the tomcat9/temp folder.

image

And all these are the jar files which have been included in the project build path. image

So after deploying the war file when I am sending a request, I am getting this 500 error in postman,

`

<!doctype html>

HTTP Status 500 – Internal Server Error

HTTP Status 500 – Internal Server Error


Type Exception Report

Message Servlet execution threw an exception

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: Servlet execution threw an exception
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

java.lang.UnsatisfiedLinkError: The specified module could not be found.

    com.sun.jna.Native.open(Native Method)
    com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:288)
    com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:427)
    com.sun.jna.Library$Handler.<init>(Library.java:179)
    com.sun.jna.Native.loadLibrary(Native.java:569)
    com.sun.jna.Native.loadLibrary(Native.java:544)
    net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:85)
    net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:42)
    net.sourceforge.tess4j.Tesseract.init(Tesseract.java:427)
    net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:311)
    net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:294)
    net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:275)
    net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:259)
    com.ReadQR.readTextfromImage(ReadQR.java:184)
    com.ReadQR.readTextAndSetPagesFromImage(ReadQR.java:213)
    com.ReadQR.ReadQr(ReadQR.java:106)
    com.Post.doPost(Post.java:58)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Note The full stack trace of the root cause is available in the server logs.


Apache Tomcat/9.0.27

`

Can you please tell me what mistake I am doing ? This is running completely fine in tomcat 9 , in windows 10 64bit.

Thank you.

nguyenq commented 2 years ago

Make sure that the app have write/read access to Tomcat's temp folder. You may want to set the system property jna.debug_load=true to print the library search paths that JNA is searching for the native libraries to load.

https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md

sanjeebsarkar commented 2 years ago

Make sure that the app have write/read access to Tomcat's temp folder. You may want to set the system property jna.debug_load=true to print the library search paths that JNA is searching for the native libraries to load.

https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md

Hi , I will check the jna.debug_load , on the other hand , tomcat is able to create a folder inside its /temp folder. So read write is not an issue.

One thing, the TESSDATA_PREFIX is added to system path, do I need to add the tess4j's dlls also to system path ?

nguyenq commented 2 years ago

The environment variable TESSDATA_PREFIX should not be added to system path; it should be set to the parent directory of your tessdata directory.

Just wanted to confirm, are you running JDK 64 bit?

sanjeebsarkar commented 2 years ago

Hi , I may have said it wrong, I have added TESSDATA_PREFIX to the environment variable, and it points to the installation/tessdata folder , this is the screenshot of the tessdata path set Windows 7. image

And , yes I am using jdk 64 biy, here is a cmd version output details of the java :

image

is there any additional setting I have to do for tomcat to help it find the dll's ?

nguyenq commented 2 years ago

TESSDATA_PREFIX variable should be set to D:\Program Files\Tesseract-OCR.

What is printed out when you run with jna.debug_load=true?

sanjeebsarkar commented 2 years ago

Hi , Please give me some time, I am working on the jna argument.

I will change the path also.

On Sat, Nov 13, 2021, 09:13 Quan Nguyen @.***> wrote:

TESSDATA_PREFIX variable should be set to D:\Program Files\Tesseract-OCR.

What is printed out when you run with jna.debug_load=true?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nguyenq/tess4j/issues/223#issuecomment-967773247, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN5BR6UHVQZHR5AXIOTZG6LULXNHJANCNFSM5H3ZJZ2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

sanjeebsarkar commented 2 years ago

Hi

Here is cmd output with the -D option added in tomcat 9,

image

Is this what you were looking for ?

nguyenq commented 2 years ago

JNA indeed tried to look up the native libraries in Tomcat's Temp directory but, for some reasons, was unable to load the DLLs found. I notice the JNA version is very old -- not sure if that could be a problem.

All I can suggest now is to create a simple console app using tess4j. Once you can get that to work, you can then try to apply to the server app.

sanjeebsarkar commented 2 years ago

Hi , Thank you for replying , Which version of JNA would you recommend ?

sanjeebsarkar commented 2 years ago

Ok , I will try to do that, can you please tell me a little bit clear as to what to do ? Create a standalone "main method" program, and create a jar file and then call it from war file ?

nguyenq commented 2 years ago

tess4j's dependencies: https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j/4.5.5

Just try a simple console app to ensure you get all the required dependencies for tess4j and get it to run. I'm not experienced with WAR packaging or Java application server to give advice on.

sanjeebsarkar commented 2 years ago

Ok, Understood.. Anyway, we can close this issue, since I am stuck on my side. I will reopen this issue once I have something to report.

Thanks for all the help.

nguyenq commented 2 years ago

Good luck. Who opened the issue can close it as well.