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());
}
}
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
In my build class path, i hame the correct jars files:
tess4j.jar
jai_imageio.jar
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
Please help!
Your jar file manifest should include a Class-Path entry:
Class-Path: tess4j.jar jai_imageio.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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With