我试图让事情与 tess4j(OCR 算法)一起工作,并且我正在使用以下代码:
import java.awt.image.RenderedImage;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;
import net.sourceforge.tess4j.*;
public static void main(String[] args) throws Exception{
URL imageURL = new URL("http://s4.postimg.org/e75hcme9p/IMG_20130507_190237.jpg");
RenderedImage img = ImageIO.read(imageURL);
File outputfile = new File("saved.png");
ImageIO.write(img, "png", outputfile);
try {
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
String result = instance.doOCR(outputfile);
System.out.println(result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
当我在 Eclipse(juno-64bit)中运行它时,它运行完美!
但是从命令行我得到这个异常:
Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/tess4j/Tesseract
at SimpleQueueServiceSample.testOCR(SimpleQueueServiceSample.java:73)
at SimpleQueueServiceSample.main(SimpleQueueServiceSample.java:57)Caused by: java.lang.ClassNotFoundException: net.sourceforge.tess4j.Tesseract
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
在我的构建类路径中,我拥有正确的 jars 文件:
tess4j.jar
jai_imageio.jar
之后,我导出一个简单的 jar 文件(这些 jar 在构建路径中的“order and export”处签名),然后运行我的代码:
java -jar manager.jar
请帮忙!