I am using Tesseract for Java for OCR text extraction, which makes JNI native calls to Leptonica system library.
When running a Quarkus application in JVM mode in a Linux-based host it resolves JNI method calls correctly,
and all works as expected. But when running as a native image, an UnsatisfiedLinkError
exception is thrown when making a call to pixReadMem
metohd, which is not found.
The stack trace when running the native image is:
2022-12-16 08:20:29,736 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (executor-thread-0) Request failed: java.lang.UnsatisfiedLinkError: Error looking up function 'pixReadMem': com.sun.jna.Native.findSymbol(JLjava/lang/String;)J [symbol: Java_com_sun_jna_Native_findSymbol or Java_com_sun_jna_Native_findSymbol__JLjava_lang_String_2]
at com.sun.jna.Function.<init>(Function.java:252)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:600)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:576)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:562)
at com.sun.jna.Library$Handler.invoke(Library.java:243)
at com.sun.proxy.$Proxy107.pixReadMem(Unknown Source)
at com.itextpdf.pdfocr.tesseract4.TesseractOcrUtil.readPix(TesseractOcrUtil.java:662)
at com.itextpdf.pdfocr.tesseract4.TesseractOcrUtil.readPix(TesseractOcrUtil.java:641)
at com.itextpdf.pdfocr.tesseract4.ImagePreprocessingUtil.preprocessImage(ImagePreprocessingUtil.java:166)
at com.itextpdf.pdfocr.tesseract4.Tesseract4LibOcrEngine.getOcrResultForSinglePage(Tesseract4LibOcrEngine.java:314)
at com.itextpdf.pdfocr.tesseract4.Tesseract4LibOcrEngine.doTesseractOcr(Tesseract4LibOcrEngine.java:189)
at com.itextpdf.pdfocr.tesseract4.AbstractTesseract4OcrEngine.processInputFiles(AbstractTesseract4OcrEngine.java:494)
at com.itextpdf.pdfocr.tesseract4.AbstractTesseract4OcrEngine.doImageOcr(AbstractTesseract4OcrEngine.java:232)
at es.gen.quarkus.ocr.service.TesseractService.extratTextFromJPG(TesseractService.java:42)
at es.gen.quarkus.ocr.service.TesseractService_ClientProxy.extratTextFromJPG(Unknown Source)
at es.gen.quarkus.ocr.service.OCRService.extractTextFromPDF(OCRService.java:34)
at es.gen.quarkus.ocr.service.OCRService_ClientProxy.extractTextFromPDF(Unknown Source)
at es.gen.quarkus.ocr.resource.OCRResource.extractTextFromPDF(OCRResource.java:46)
at es.gen.quarkus.ocr.resource.OCRResource$quarkusrestinvoker$extractTextFromPDF_21209ffb320090ffe15503899b13ececc74cb601.invoke(Unknown Source)
at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:114)
at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:145)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at [email protected]/java.lang.Thread.run(Thread.java:829)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)`
```
I have tried to set Java system properties with no success:
- `java.library.path` (the current value includes the linux system folders).
- `jna.debug_load=true` does not log any information.
Add this to properties
install libtesseract5 because latest code uses that. this is how I installed it
then I manage to get the runner executable. no need to run install just mvn package -Pnative will do fine. When I ran in my local and send a pdf, got another exception.
build log to show versions
what libraries it depends