java tess4j ddl,分配为war NoClassDefFoundError后出现Tess4J错误:无法初始化类net.sourceforge.tess4j.TessAPI…「建议收藏」

java tess4j ddl,分配为war NoClassDefFoundError后出现Tess4J错误:无法初始化类net.sourceforge.tess4j.TessAPI…「建议收藏」IhaveSpringbootWebserverprojectwhichworksokinmyPCunderIntellijIDEA,butitnotworksafterdistributingtothesamePCaswarfile-NoClassDefFoundError:Couldnotinitializeclassnet…

大家好,又见面了,我是你们的朋友全栈君。

java tess4j ddl,分配为war NoClassDefFoundError后出现Tess4J错误:无法初始化类net.sourceforge.tess4j.TessAPI...「建议收藏」

I have Spring boot Webserver project which works ok in my PC under Intellij IDEA, but it not works after distributing to the same PC as war file – NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.TessAPI.

my code:

ITesseract instance = new Tesseract(); // JNA Interface Mapping

instance.setDatapath(new File(datapath).getPath());

instance.setLanguage(“eng”);

try {

String result = instance.doOCR(imageFile);

} catch (TesseractException e) {

System.err.println(e.getMessage());

}

I have only one maven dependency, releted to Tess4J:

net.sourceforge.tess4j

tess4j

3.0.0

I’ve got the error after running my distributed war:

There was an unexpected error (type=Internal Server Error, status=500).

Could not initialize class net.sourceforge.tess4j.TessAPI

Full Tomcat log:

java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.TessAPI

at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:367) ~[tess4j-3.0.0.jar:3.0.0]

at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:280) ~[tess4j-3.0.0.jar:3.0.0]

at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212) ~[tess4j-3.0.0.jar:3.0.0]

at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:196) ~[tess4j-3.0.0.jar:3.0.0]

at ocr.OCRController.handleFileUpload(OCRController.java:127) ~[classes/:0.3.0]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]

at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]

at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]

at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]

How can I fix the error? I have the plan to host this app in Windows Azure under Tomcat. Thank you for any help, friends!

解决方案

The problem was in temp folder – it does not contain all necessary dlls.

Info for community:

1. Check temp folder under tomact – for me the path to it is:

D:\Programs_Files\apache-tomcat-8.0.27\temp

This temp folder MUST contain the directory tess4j\win32-x86-64 with next 3 files: gsdll64.dll, liblept171.dll, libtesseract304.dll (or your version)

I had my problem because the directory tess4j\win32-x86-64 have never been created in temp.

BUT

My app works ok under Intellij IDEA because another Temp folder (for IDEA) works ok – C:\Users\Iuliia\AppData\Local\Temp\

contains tess4j\win32-x86-64\gsdll64.dll, tess4j\win32-x86-64\liblept171.dll, tess4j\win32-x86-64\libtesseract304.dll as expected.

Note, that this files are created in process of calling Tesseract in your code. Not early.

HOW I FIX THE PROBLEM with temp under Tomcat

I’ve added win32-x86-64\gsdll64.dll, win32-x86-64\liblept171.dll, win32-x86-64\libtesseract304.dll to the resources directory in my project.

Look at my project structure:

image.jpg

After deploying to tomcat, the necessary dlls is under classes directory (important!) – it means they are is in the scope.

image.jpg

Now it will be added to

D:\Programs_Files\apache-tomcat-8.0.27\temp\tess4j\win32-x86-64 as expected.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/142895.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MySQL数据库建表语句

    MySQL数据库建表语句**建立一个叫student的表**CREATETABLE`student`(**id为int类型设置不能为空值**`id`INTNOTNULLauto_incrementprimarykeyCOMMENT’学生id’,`name`VARCHAR(16)NOTNULLCOMMENT’学生姓名’,`sex`CHAR(1)DEFAULT’男’COMMENT’性别’…

    2022年9月8日
    2
  • log4cpp学习

    log4cpp学习1、linux下log4cpp的下载安装配置http://log4cpp.sourceforge.net/官方网站有下载地址,安装过程配置选项及测试用例。将下载好的tar包解压到/usr/local/下运行./configure(如有需要添加相关配置选项),使用make编译,使用makecheck进行检测,使用makeinstall安装,使用之前的相关命令安装好之后在/usr

    2022年7月13日
    16
  • 平均数,中位数,众数的特点及应用场合图片_中位数众数应用例子

    平均数,中位数,众数的特点及应用场合图片_中位数众数应用例子平均数、中位数、众数都是度量一组数据集中趋势的统计量。所谓集中趋势是指一组数据向某一中心值靠拢的倾向,测度集中趋势就是寻找数据一般水平的代表值或中心值。而这三个特征数又各有特点,能够从不同的角度提供信息。平均数特点:计算用到所有的数据,它能够充分利用数据提供的信息,它具有优的数学性质,因此在实际应用中较为广泛。但它受极端值的影响较大。应用场合:没有极端值的情况下数据集中趋势的刻画。

    2022年9月16日
    2
  • gb28181协议详解_GB28181收费吗

    gb28181协议详解_GB28181收费吗ssdp协议近似于http协议,事实上,和http协议相似得地方就是他得协议内容,当然,我们要去除他得端口和d类地址。为什么我在给其他员工或者面试得时候要他人深入一些,理解一下http协议,是因为理解了http协议,掌握ssdp也就不远了,很多人可能会问http协议有啥内容,无非就是get,post,put,delete么,还能怎么样,我经常问他们一点http协议怎么知道他结束了?虽然ssdp是udp协议,但是他依然需要\r\n来代表行结束,\r\n\r\n代表协议内容部分结束。……

    2022年10月11日
    1
  • java全局变量引起的并发问题「建议收藏」

    java全局变量引起的并发问题「建议收藏」最近刚完成了一个短彩信群发平台的开发工作,系统采用springmvc+hibernate+jdbctemplate+mysql架构。其中遇见许多问题,闲暇之余记录下来以避免在后续项目中再犯同样的错误。先看下面小段代码,一个controller,一个service。       controller.java代码:    ……..    @Autowired

    2022年8月21日
    8
  • CAS单点登录与部署

    CAS单点登录与部署

    2021年8月24日
    56

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号