我正在使用Java Sprint和Eclipse中的Maven开发应用程序。
我在Windows中使用我的开发机器上的tesseract工作(是的,我知道......)但是当我尝试在Centos 7的服务器中部署应用程序时,我收到一些错误,应用程序停止工作..
pom.sml
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>tesseract-platform</artifactId>
<version>3.04.01-1.3</version>
</dependency>
我的代码:
BytePointer outText;
TessBaseAPI api = new TessBaseAPI();
if (api.Init(ResourcesLocation.getTestData(), "spa") != 0) {
System.err.println("Could not initialize tesseract.");
response.setSuccess(false);
response.setCode(CodeList.EXCEPTION);
}
else{
// Open input image with leptonica library
PIX image = pixRead(file);
api.SetImage(image);
// Get OCR result
outText = api.GetUNLVText();
data = this.cleanData(outText.getString().split("\\r?\\n"));
// Destroy used object and release memory
api.End();
outText.deallocate();
pixDestroy(image);
}
api.close();
在运行时我得到:
Estado HTTP 500 – Internal Server Error
Tipo Informe de Excepción
mensaje Handler processing failed; nested exception is java.lang.ExceptionInInitializerError
descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.
excepción
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.ExceptionInInitializerErrororg.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1302)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)javax.servlet.http.HttpServlet.service(HttpServlet.java:661)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)com.invoicebox.security.JWTTokenAuthFilter.doFilterInternal(JWTTokenAuthFilter.java:157)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
causa raÃz
java.lang.ExceptionInInitializerErrorjava.lang.Class.forName0(Native Method)java.lang.Class.forName(Class.java:348)org.bytedeco.javacpp.Loader.load(Loader.java:585)org.bytedeco.javacpp.Loader.load(Loader.java:530)org.bytedeco.javacpp.tesseract$TessBaseAPI.<clinit>(tesseract.java:3648)com.invoicebox.services.InvoiceServiceImpl.importInvoice(InvoiceServiceImpl.java:350)com.invoicebox.services.InvoiceServiceImpl.save(InvoiceServiceImpl.java:1422)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)com.sun.proxy.$Proxy1573.save(Unknown Source)com.invoicebox.controller.InvoiceController.save(InvoiceController.java:138)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)javax.servlet.http.HttpServlet.service(HttpServlet.java:661)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)com.invoicebox.security.JWTTokenAuthFilter.doFilterInternal(JWTTokenAuthFilter.java:157)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
causa raÃz
java.lang.NullPointerExceptionorg.bytedeco.javacpp.Loader.cacheResource(Loader.java:334)org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:772)org.bytedeco.javacpp.Loader.load(Loader.java:604)org.bytedeco.javacpp.Loader.load(Loader.java:530)org.bytedeco.javacpp.lept.<clinit>(lept.java:10)java.lang.Class.forName0(Native Method)java.lang.Class.forName(Class.java:348)org.bytedeco.javacpp.Loader.load(Loader.java:585)org.bytedeco.javacpp.Loader.load(Loader.java:530)org.bytedeco.javacpp.tesseract$TessBaseAPI.<clinit>(tesseract.java:3648)com.invoicebox.services.InvoiceServiceImpl.importInvoice(InvoiceServiceImpl.java:350)com.invoicebox.services.InvoiceServiceImpl.save(InvoiceServiceImpl.java:1422)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)com.sun.proxy.$Proxy1573.save(Unknown Source)com.invoicebox.controller.InvoiceController.save(InvoiceController.java:138)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)javax.servlet.http.HttpServlet.service(HttpServlet.java:661)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)com.invoicebox.security.JWTTokenAuthFilter.doFilterInternal(JWTTokenAuthFilter.java:157)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
nota La traza completa de la causa de este error se encuentra en los archivos de diario del servidor.
我在this example之后安装了Tesseract和Leptonica(但我更改了西班牙语的语言)
我可以从那里得到的是应用程序在执行时崩溃:
TessBaseAPI api = new TessBaseAPI();
答案 0 :(得分:1)
最终的解决方案是从Java应用程序运行命令以执行包括dessire参数的tesseract,并将结果写在文本文件中。之后,java应用程序读取文本文件,这就是全部!
没有API,没有外部库,没有更多问题...