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.

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(1)


相关推荐

  • Ubuntu安装gcc失败的那些事儿「建议收藏」

    Ubuntu安装gcc失败的那些事儿「建议收藏」想在虚拟机上运行一个C程序输入gcc-ohellohello.c编译C语言文件嗯?找不到gcc。。。那就下载gcc输入gcc安装命令sudoaptinstallgcc安装包即将下完的时候提示下载错误,(我滴天,什么人间疾苦!!!)有几个软件包下载不了,还建议我使用sudoapt-getupdate或者加上–fix-missing那就屈尊采纳一下它的建议使用sudoapt-getupdate更新了一下软件资源(然并卵。。。)再试一下sudoaptinstallgc

  • matlab如何使用random函数,random函数

    matlab如何使用random函数,random函数手机评站网今天精心准备的是《random函数》,下面是详解!random函数的用法是turbopascal中的函数,希望有具体的介绍(有程序最好)…是turbopascal中的函数,希望有具体的介绍(有程序最好)用法:1、随机生成(0,1)之间的浮点数random.random()2、随机生成100-200的整数random.randint(100,200)3、随机产生范围为10间隔为2的…

  • SHFileOperation 文件夹COPY「建议收藏」

    SHFileOperation 文件夹COPY「建议收藏」/********************************************************函数名:CopyFolder函数功能:文件夹复制输入参数:lpszFromPath,lpszFromPath返回值:True说明:源目录必须以’\0\0′(即连续的两个’\0′)结束,不能以’\’结束*******************************

  • perl json encode_json decode_json

    perl json encode_json decode_jsonuse之后使用encode_json命令即可将perl的array或者dic转换为标准的JSON字符串了:jrhmpt01:/root/wx#catjson.pluseJSONqw/encode_jsondecode_json/;my$data=[{‘name’=>’Ken’,’age’=>19},

  • http://oncenote.com/2015/09/16/Security-2-HTTPS2/ (轉載)

    http://oncenote.com/2015/09/16/Security-2-HTTPS2/ (轉載)上一篇《iOS安全系列之一:HTTPS》被CocoaChina转载,还顺便上了下头条:打造安全的App!iOS安全系列之HTTPS,但那篇文章只是介绍了比较偏应用的初级知识,对于想要深入了解HTT

  • Ambari HDP集群搭建全攻略「建议收藏」

    Ambari HDP集群搭建全攻略「建议收藏」世界上最快的捷径,就是脚踏实地,本文已收录【架构技术专栏】关注这个喜欢分享的地方。最近因为工作上需要重新用Ambari搭了一套Hadoop集群,就把搭建的过程记录了下来,也希望给有同样需求的小伙伴们

发表回复

您的电子邮箱地址不会被公开。

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