问题描述
我试图使事情与tess4j(OCR算法)一起工作,我使用以下代码:
I am try to make things works with tess4j (OCR algorithm), and i m using this code:
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)中运行它时,它运行完美!
When i run it in Eclipse (juno-64bit) it works perfect!
但是从命令行我得到了这个异常:
But from the command line i get this Exception:
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
在我的构建类路径中,我有正确的jar文件:
In my build class path, i hame the correct jars files:
tess4j.jar
jai_imageio.jar
此后,我导出一个简单的jar文件(jar在构建路径中的"order and export"处签名),然后运行我的代码:
After that i export a simple jar file (the jars are sign at 'order and export' in the build path), and run my code:
java -jar manager.jar
请帮助!
推荐答案
Class-Path: tess4j.jar jai_imageio.jar
然后在执行时将这些jar文件放置在与jar文件相同的目录中,以便可以适当地加载它们.
Those jar files should then be placed in the same directory as your jar file at execution time, so they can be loaded appropriately.
到那时,一切都应该很好.但是,如果清单中没有该条目,则无法将您的jar文件与其依赖的其他jar文件连接起来.
At that point, all should be well. But without that entry in the manifest, there's nothing to connect your jar file with the other jar files it depends on.
这篇关于Java异常-线程"main"中的异常; java.lang.NoClassDefFoundError:net/sourceforge/tess4 j/Tesseract的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!