【问题标题】:java.lang.NoClassDefFoundError: net/sourceforge/tess4j/TesseractExceptionjava.lang.NoClassDefFoundError: net/sourceforge/tess4j/TesseractException
【发布时间】:2022-04-10 15:21:16
【问题描述】:

我尝试用 Java 和 Tesseract 为 Mirth 做一个 ocr 应用程序。我将项目导出到 jar 文件中,并用 Javascript 调用 Mirth,它做了一个 hello world 应用程序。我相信我以正确的方式添加 jar 文件。但是我Java OCR 有问题,所以我得到这个错误,

错误 (com.mirth.connect.connectors.js.JavaScriptDispatcher:193):评估 JavaScript 编写器时出错(通道 b469e5af-a78d-41ca-86a0-a7b507799a4d 上的 JavaScript 编写器“RTF>DCM”)。 java.lang.NoClassDefFoundError: net/sourceforge/tess4j/TesseractException

Project Screenshot

package com.imagerad.ocr;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

public class JavaOCRTest {
static String Tc;
static String phone;
static String date;

public static void main(String[] args) throws IOException{

}

public String returnText(String fileName) throws IOException{


    Files.walk(Paths.get(fileName)).forEach(filePath -> {
        if (Files.isRegularFile(filePath)) {
            File imageFile = filePath.toFile();

            ITesseract instance = new Tesseract();

            try {
                String result = instance.doOCR(imageFile);

                int i=result.indexOf("Numarasn: ");
                int j=result.indexOf("Tel No:");
                int k=result.indexOf("Bilgllendirme Tarihl:");

                Tc = result.substring(i+10, i+22);
                phone = result.substring(j+8,j+23);
                date = result.substring(k+22,k+32);


            } catch (TesseractException e) {
                System.err.println(e.getMessage());
            }
        }
    });
    return Tc+""+phone+""+date;
}

public String returnTC() throws IOException{
    return Tc;
}

public String returnPhone() throws IOException{
    return phone;
}

public String returnDate() throws IOException{
    return date;
}
}

非常感谢您的帮助。

【问题讨论】:

  • 这是一个找不到类的异常,因此请仔细检查相关 jar 的路径以及 jar 文件是否确实具有您认为它们应该具有的类(使用 unzip -l file.jar)。
  • 谢谢@Robert。我解决了我的问题。你可以看到所有答案this

标签: java tesseract mirth tess4j


【解决方案1】:

您必须下载Tess4J.jar 并将其添加到类路径中。此 jar 包含缺少的类 net/sourceforge/tess4j/TesseractException

【讨论】:

  • 我怎样才能在这个类路径中添加它?也许我以前做过。
  • 你是如何上课的?
  • 我已经通过 Java Build Path -> Libraries -> Add External JARs 添加了 Tess4J 的 jar 文件。项目也在本地运行。
猜你喜欢
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
  • 2022-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多