分配为war NoClassDefFoundError后出现Tess4J错误:无法初始化类net.sourceforge.tess4j.TessAPI [英] Tess4J error after distributing as war NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.TessAPI

查看:2391
本文介绍了分配为war NoClassDefFoundError后出现Tess4J错误:无法初始化类net.sourceforge.tess4j.TessAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Spring boot Webserver项目,该项目在Intellij IDEA下可以在我的PC上正常运行,但是在分发到与war文件相同的PC后无法正常工作- NoClassDefFoundError:无法初始化类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.

我的代码:

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());
 }

我只有一个maven依赖项,重新命名为Tess4J:

I have only one maven dependency, releted to Tess4J:

<dependency>
        <groupId>net.sourceforge.tess4j</groupId>
        <artifactId>tess4j</artifactId>
        <version>3.0.0</version>
</dependency>

进行分布式战争后出现错误:

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

完整的Tomcat日志:

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]

如何解决该错误?我计划在Tomcat下的Windows Azure中托管此应用程序.谢谢您的帮助,朋友们!

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!

推荐答案

问题出在temp文件夹中-它不包含所有必需的dll.

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

社区信息: 1.检查tomact下的temp文件夹-对我来说,它的路径是: D:\Programs_Files\apache-tomcat-8.0.27\temp

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

此临时文件夹必须包含以下三个文件的目录tess4j \ win32-x86-64: gsdll64.dll,liblept171.dll,libtesseract304.dll (或您的版本)

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

我遇到了问题,因为从未在临时目录中创建过tess4j \ win32-x86-64目录.

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

但是

我的应用程序在Intellij IDEA下可以正常工作,因为另一个Temp文件夹(对于IDEA)可以正常工作-C:\Users\Iuliia\AppData\Local\Temp\

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

按预期包含tess4j \ win32-x86-64 \ gsdll64.dll,tess4j \ win32-x86-64 \ liblept171.dll,tess4j \ win32-x86-64 \ libtesseract304.dll.

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

请注意,此文件是在您的代码中调用Tesseract的过程中创建的.不早

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

如何在Tomcat下使用temp解决问题

我已将win32-x86-64 \ gsdll64.dll,win32-x86-64 \ liblept171.dll,win32-x86-64 \ libtesseract304.dll添加到项目中的 resources 目录中

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:

部署到tomcat后,必需的dll在classes目录下(重要!)-这意味着它们在作用域内.

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

现在它将被添加到

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

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

这篇关于分配为war NoClassDefFoundError后出现Tess4J错误:无法初始化类net.sourceforge.tess4j.TessAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆