Reputation: 535
I am trying to use tess4j into my java program. Here is my code:
`import java.io.File;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
class Test {
public static void main(String[] args)
{
Tesseract tesseract = new Tesseract();
try {
String text = tesseract.doOCR(new File("captcha.jpg"));
System.out.print(text);
}
catch (TesseractException e) {
e.printStackTrace();
}
}
}
I am getting these error messages
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Pointer
at Test.main(Detection.java:9)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Pointer
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
My folder looks like this:
Main folder:
Detection.java
lib -> Here I have the "tess4j-3.4.8.jar" file I got after downloading the tess4j and going into the dist folder
.captcha.jpg
I am not able to solve this issue. Please help.
I am using visual studio code as my IDE.
Upvotes: 1
Views: 11257
Reputation: 81
The solution above of YogendraR worked. You have to add the jar files in the lib folder of your tess4J folder in your project struture Project structure => Module => Dependencies. The jars files to add
Upvotes: 3
Reputation: 2376
tess4j
has following transitive dependencies:
You will need to include these in your classpath.
PS: You should use some build tool: maven or gradle
Upvotes: 3