Shobhit Tewari
Shobhit Tewari

Reputation: 535

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Pointer

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:

  1. Detection.java

  2. lib -> Here I have the "tess4j-3.4.8.jar" file I got after downloading the tess4j and going into the dist folder

  3. .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

Answers (2)

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

Add them here

Upvotes: 3

YogendraR
YogendraR

Reputation: 2376

tess4j has following transitive dependencies:

enter image description here

You will need to include these in your classpath.

PS: You should use some build tool: maven or gradle

Upvotes: 3

Related Questions