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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • Java开发人员必须掌握的Linux命令(三)

    做一个积极的人编码、改bug、提升自己我有一个乐园,面向编程,春暖花开!学习应该是快乐的,在这个乐园中我努力让自己能用简洁易懂(搞笑有趣)的表达来讲解知识或者技术,让学习之旅充满乐趣,这就是写博文的初心。前面写了两篇Linux的命令介绍,地址1 地址2 ,前段时间看了哈利波特的一些电影,突然想到Linux的命令就像哈利波特电影中的魔法一样,都是有魔力的。那么学会Linux的这些命令,我…

    2022年2月28日
  • Python 列表元素字符串转浮点

    Python 列表元素字符串转浮点在网络爬虫或者读取文件中的数据时,很多时候读取出来的数值是字符串形式的,这些字符串形式的数据并不能用来作计算或者更深入的操作,因此我们需要把他们转换为数值的形式。简单粗暴的for循环假设,这里有一个以字符串形式存储数值的列表,具体如下:a=[‘2′,’3.5′,’10’,’88’,’32.66′]我们需要将其转换为浮点的形式,最简单粗暴直接的方法,可以使用…

    2022年6月1日
  • DNS服务器配置和测试

    DNS服务器配置和测试DNS服务器配置和测试

    2022年5月16日
  • vue前后台数据交互vue-resource文档

    vue前后台数据交互vue-resource文档

    2021年10月11日
  • HTML/CSS面试题(收集)[通俗易懂]

    HTML/CSS面试题(收集)[通俗易懂]1、目前主流的浏览器以及其内核名有哪些?点这里查看2、内元素和块级元素的区别?行内元素:不会独立出现在一行,单独使用的时候后面不会有换行符的元素。eg:span,strong,img,a等。这些元素,默认的高宽,总是其内容的高宽。并且,margin和padding值,只有左右有效。块级元素:独立在一行的元素,他们后面会自动带有换行符。eg:di

    2022年5月20日
  • java语言的特性有什么

    java语言的特性有什么1.java语言是简单的java语言是和c++语言类似的,其次java中丢弃了c++中一些难理解的特性,比如运算符重载等,java语言不使用指针,并且拥有垃圾回收机制2.java语言是面向对象的java语言提供了类、接口和继承等特性,只支持类之间的单继承,但是支持接口之间的多继承,并且支持类与接口之间的实现机制,而且java是全面支持动态绑定的。3.java语言是分布式的jav…

    2022年7月7日

发表回复

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

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