2016-08-19 334 views
0

我尝试使用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

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

非常感谢你对你的帮助。

+0

这是一个没有发现异常的类,所以仔细检查问题罐子的路径,并确认jar文件实际上有你认为应该有的类(使用'unzip -l file.jar ')。 – Robert

+0

谢谢你@ Robert.I解决了我的问题。你可以看到所有的答案[this](http://stackoverflow.com/a/39201494/5459257) –

回答

2

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

+0

我该如何添加这个类路径?也许我之前做过。 –

+0

你如何运行课程? – Jens

+0

我已经通过Java Build Path - > Libraries - > Add External JARs为Tess4J添加了jar文件。这个项目也在本地运行。 –