我嘗試使用Java和Tesseract爲Mirth做一個ocr應用程序。我將這個項目導出到jar文件中,然後在JavaScript中調用一個Hello World應用程序。我相信,我添加的jar文件正確way.However我在Java的OCR一個問題,所以我得到這個錯誤,java.lang.NoClassDefFoundError:net/sourceforge/tess4j/TesseractException
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
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文件實際上有你認爲應該有的類(使用'unzip -l file.jar ')。 – Robert
謝謝你@ Robert.I解決了我的問題。你可以看到所有的答案[this](http://stackoverflow.com/a/39201494/5459257) –