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)
上一篇 2022年5月10日 下午7:40
下一篇 2022年5月10日 下午8:00


相关推荐

  • 常见的动态路由协议(RIP、OSPF、ISIS、BGP)

    常见的动态路由协议(RIP、OSPF、ISIS、BGP)路由器要转发数据必须先配置路由数据 通常根据网络规模的大小可设置静态路由或设置动态路由 静态路由配置方便 对系统要求低 适用于拓扑结构简单并且稳定的小型网络 缺点是不能自动适应网络拓扑的变化 需要人工干预 动态路由协议有自己的路由算法 能够自动适应网络拓扑的变化 适用于具有一定数量三层设备的网络 缺点是配置对用户要求比较高 对系统的要求高于静态路由 并将占用一定的网络资源 nbsp nbsp nbsp nbsp nbsp nbsp

    2026年3月18日
    2
  • 收藏必备:从零开始使用n8n+大模型搭建微信公众号自动发布工作流(实战教程)

    收藏必备:从零开始使用n8n+大模型搭建微信公众号自动发布工作流(实战教程)

    2026年3月15日
    3
  • weka算法介绍

    weka算法介绍转载 http blog sina com cn s blog 8bdd25f80101 html1 数据输入和输出 nbsp WOW 查看 Weka 函数的参数 nbsp Weka control 设置 Weka 函数的参数 nbsp read arff 读 WekaAttribut RelationFile ARFF 格式的数据 nbsp write arff 将数

    2026年3月17日
    2
  • Restore Points 制定回退方案「建议收藏」

    Restore Points 制定回退方案

    2022年3月1日
    40
  • 操作系统习题(有一个具有两道作业的批处理系统)

    操作系统习题(有一个具有两道作业的批处理系统)题目描述 有一个具有两道作业的批处理系统 作业调度采用短作业优先的调度算法 进程调度采用以优先数为基础的抢占式调度算法 在下表所示的作业序列 作业优先数即为进程优先数 优先数越小优先级越高 1 列出所有作业进入内存时间及结束时间 2 计算平均周转时间 解析 首先我们来分析题意 第一句话很重要 一个具有两道作业的批处理系统 这句话是什么意思呢 在引入了多道程序设计计数后 内存可以同时存放多个用户作业 并使它们交替运行 轮流使用 cpu 和 I O 设备 使系统资源利用率提高 题目告诉我们是两道作业的批处

    2026年3月19日
    3
  • VSCode 配置Java环境「建议收藏」

    VSCode 配置Java环境「建议收藏」VSCode配置Java环境闲话少说,开始配置挚爱的VSCode!!!第一步,安装VScode小插件第二步,简单写个测试代码然后进入setting.json替换以下代码第三步,配置launch.json好了,到此完成,希望能帮到大家!!!有问题可以留言共同探讨哦!!![点击这里转到Wondows配置java环境,配置完之后再到这个文章看VSCode配置](https://blog.c…

    2022年5月23日
    231

发表回复

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

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