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


相关推荐

  • 防火墙

    防火墙

    2021年6月11日
    112
  • 免备案空间收集

    免备案空间收集用了这个国外的免备空间,觉得其他的都弱爆了此空间无广告,大空间,速度快,而且是即时开通的,我去截图分享下。虽然是美国的,但是提供中文申请页面,但是用谷歌浏览器可以无障碍设置。这是登录进去时候的页面:这个是我目前的两个域名,每过24小时可以创建一个。这个是控制面板这个是我的账户信息可以看一下磁盘容量和带宽,都是大到用不完···,跟其他的需要付神马1块两块钱别人才提供给…

    2022年6月18日
    21
  • filter suction_dispatcher

    filter suction_dispatcherFilterDispatcher是struts2.0.x到2.1.2版本的核心过滤器.! StrutsPrepareAndExecuteFilter是自2.1.3开始就替代了FilterDispatcher的.!  StrutsPrepareAndExecuteFilter概要说明        FilterDispatcher是早期struts2的过滤器,后期的都…

    2022年8月16日
    2
  • LaTeX的安装教程(Texlive 2020 + TeX studio)

    LaTeX的安装教程(Texlive 2020 + TeX studio)LaTeX安装步骤1、TexLive安装1.1下载TexLive1.2安装TexLive1、TexLive安装1.1下载TexLive点击TexLive使用清华镜像进行下载。如下图所示。1.2安装TexLive1.2.1打开下载后的.ISO文件,如下图所示。以管理员身份运行install-tl-windows.bat文件。1.2.2运行后的界面如下图所示。软件的安装路径默认为C盘,这里可以修改为其他磁盘。1.2.3修改好软件的安装路径后,点击Advanced,

    2022年6月11日
    50
  • SpringBoot — 软件许可(License)证书生成+验证+应用完整流程

    SpringBoot — 软件许可(License)证书生成+验证+应用完整流程一、项目目录树结构由于时间有限,不可能在博客上花太多时间、也不可能每一个细节都说的很细,所以,下面的内容虽然一时间看着比较懵,但是文末有项目的GitHub地址,或者不懂的可以留言;这个是粗糙的项目结构,没有细分,实际应用的话应该是授权的代码要和验证的代码分开,防止授权的代码引进客户端系统中,被激活成功教程和拆穿,也为了防止公钥st…

    2022年7月26日
    25
  • 品优购-day03笔记-完善品优购的首页&制作列表页「建议收藏」

    品优购-day03笔记-完善品优购的首页&制作列表页「建议收藏」typora-copy-images-to:media第01阶段.WEB基础:品优购-day03笔记-完善品优购的首页&制作列表页学习目标完善品优购项目的首页index.html制作品优购项目的列表页list.html品优购项目(三)第01阶段.WEB基础:品优购-day02笔记-品优购首页1.品优购首页布局命名集合:名称说明…

    2022年5月8日
    58

发表回复

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

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