nguyenq / tess4j

Java JNA wrapper for Tesseract OCR API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

sanjeebsarkar opened this issue · comments

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>

<title>HTTP Status 500 – Internal Server Error</title> <style type="text/css"> h1 { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; font-size: 22px; }
	h2 {
		font-family: Tahoma, Arial, sans-serif;
		color: white;
		background-color: #525D76;
		font-size: 16px;
	}

	h3 {
		font-family: Tahoma, Arial, sans-serif;
		color: white;
		background-color: #525D76;
		font-size: 14px;
	}

	body {
		font-family: Tahoma, Arial, sans-serif;
		color: black;
		background-color: white;
	}

	b {
		font-family: Tahoma, Arial, sans-serif;
		color: white;
		background-color: #525D76;
	}

	p {
		font-family: Tahoma, Arial, sans-serif;
		background: white;
		color: black;
		font-size: 12px;
	}

	a {
		color: black;
	}

	a.name {
		color: black;
	}

	.line {
		height: 1px;
		background-color: #525D76;
		border: none;
	}
</style>

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.&lt;init&gt;(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.&lt;clinit&gt;(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.

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

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 ?

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?

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 ?

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

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

Hi

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

image

Is this what you were looking for ?

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.

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

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 ?

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.

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.

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