Search code examples
javatesseractmirthtess4j

java.lang.NoClassDefFoundError: net/sourceforge/tess4j/TesseractException


I try to do an ocr application for Mirth with Java and Tesseract.I export the project in jar file and call in Mirth with Javascript that did a hello world application.I believe that I add the jar files right way.However I have a problem in Java OCR,so I get this error,

ERROR (com.mirth.connect.connectors.js.JavaScriptDispatcher:193): Error evaluating JavaScript Writer (JavaScript Writer "RTF>DCM" on channel b469e5af-a78d-41ca-86a0-a7b507799a4d). 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;
}
}

Thank you so much for your helps.


Solution

  • You have to download the Tess4J.jar and add it to the classpath. This jar contains the missing class net/sourceforge/tess4j/TesseractException