Results 1 to 19 of 19
  1. #1
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Tesseract - Javac fails, probaly cannot find right jar files

    Hi!
    I downloaded Tesseract files java wrapper from Tess4J
    They had an example script and I am trying to test that.
    Code:
    Java Code:
    package net.sourceforge.tess4j.example;
    import java.io.File;
    import net.sourceforge.tess4j.*;
    public class TesseractExample {
        public static void main(String[] args) {
            File imageFile = new File("c:\\work\\java\\pngs\\test1.jpg");
            Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
            //Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
            try {
                String result = instance.doOCR(imageFile);
                System.out.println(result);
            } catch (TesseractException e) {
                System.err.println(e.getMessage());
            }
        }
    }
    Result:
    XML Code:
    [INDENT]C:\work\java\second>dir
     Volume in drive C has no label.
     Volume Serial Number is 58A6-0C50
    
     Directory of C:\work\java\second
    
    16.12.2013  18:54    <DIR>          .
    16.12.2013  18:54    <DIR>          ..
    28.02.2013  22:17            31*679 ghost4j-0.3.1.jar
    14.12.2013  23:51             1*839 HelloWorld.class
    15.12.2013  21:58             1*824 HelloWorld.java
    28.02.2013  22:17         1*140*632 jai_imageio.jar
    28.07.2013  13:21           914*639 jna.jar
    28.02.2013  22:17           253*160 junit-4.10.jar
    15.12.2013  23:22             1*068 MyOcrTest.class
    16.12.2013  00:12               566 MyOcrTest.java
    16.12.2013  18:55               624 TesseractExample.java
    13.12.2013  19:24               118 test.java
                  10 File(s)      2*346*149 bytes
                   2 Dir(s)  80*082*075*648 bytes free
    
    C:\work\java\second>javac TesseractExample.java
    TesseractExample.java:7: error: cannot find symbol
            Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
            ^
      symbol:   class Tesseract
      location: class TesseractExample
    TesseractExample.java:7: error: cannot find symbol
            Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
                                 ^
      symbol:   variable Tesseract
      location: class TesseractExample
    TesseractExample.java:13: error: cannot find symbol
            } catch (TesseractException e) {
                     ^
      symbol:   class TesseractException
      location: class TesseractExample
    3 errors
    
    C:\work\java\second>echo %CLASSPATH%
    .;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip
    C:\work\java\second>[/INDENT]
    Othe scripts that doesn't use external packages (or libraries, am I right?) are OK. Can compile and execute. Am I missing something?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    Yes, you are missing the classpath in the javac command.
    You need a '-cp .;<list of ; separated jar files>' in there to tell the compiler where it should be looking for the relevant classes.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    Quote Originally Posted by Tolls View Post
    Yes, you are missing the classpath in the javac command.
    You need a '-cp .;<list of ; separated jar files>' in there to tell the compiler where it should be looking for the relevant classes.
    Thanks!
    If I echo the classpath variable, it shows that values are "." and one zip file. Those 4 jar files I found with Tess4J wrapper I copied to
    - C:\Program Files (x86)\Java\jre7\lib\ext\
    - C:\work\java\second
    so I assume that when I run javac without -cp flag as i did, it should read those jar files because "they are on classpath"?
    Java Code:
    C:\work\java\second>echo %CLASSPATH%
    .;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip
    Am I right?

  4. #4
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    Thanks - I managed to compile the project - there was one more jar file but not under Tess4J/lib but Tess4J/dist.

    But executing with command
    "C:\work\java\second>java -cp .;ghost4j-0.3.1.jar;jai_imageio.jar;jna.jar;junit-4.10.jar;tess4j.jar TesseractExample"
    gave me error:
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: TesseractExample (wrong name: net/sourceforge/tess4j/example/TesseractExample)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            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)
            at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
    Is it also some kind of files-are-not-in-right-place issue?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    Quote Originally Posted by rothe View Post
    Am I right?
    Yes, it's pulling the jar files from that classpath. Quicktime is a pain in that it sets the CLASSPATH env variable, which is (frankly) bad practice.

    Note, do not stick stuff in your JRE/JDK directories. Dependencies for a project should be kept with the project.

    Quote Originally Posted by rothe View Post
    Is it also some kind of files-are-not-in-right-place issue?
    That's because your folder structure for your class has to match the package structure declared at the top of your class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    Quote Originally Posted by Tolls View Post
    That's because your folder structure for your class has to match the package structure declared at the top of your class.
    I feel really stupid. This folder structure comes from
    Java Code:
    package net.sourceforge.tess4j.example;
    or
    Java Code:
    import net.sourceforge.tess4j.*;
    and I should have under my project folder "c:\work\java\scecond\"
    subfolders "net\sourceforge\tess4j\" ?

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    It's the package declaration of your class, not the import of other classes.
    And it goes wherever you want to have your source files.

    Here's the tutorial on packages.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    Thanks I studied for a while this java folder structure (as you see 2 weeks have been passed :)) and I thought that I got the point but probably not. The file compiles without errors:
    Java Code:
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>tess1.bat
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>javac -cp .;
    ..\..\..\..\..\lib\ghost4j-0.3.1.jar;
    ..\..\..\..\..\lib\jai_imageio.jar;
    ..\..\..\..\..\lib\jna.jar;
    ..\..\..\..\..\lib\junit-4.10.jar;
    ..\..\..\..\..\dist\tess4j.jar TesseractExample.java
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>tess11.bat
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>java -cp .;
    ..\..\..\..\..\lib\ghost4j-0.3.1.jar;
    ..\..\..\..\..\lib\jai_imageio.jar;
    ..\..\..\..\..\lib\jna.jar;
    ..\..\..\..\..\lib\junit-4.10.jar;
    ..\..\..\..\..\dist\tess4j.jar TesseractExample
    
    Exception in thread "main" java.lang.NoClassDefFoundError: TesseractExample (wro
    ng name: net/sourceforge/tess4j/example/TesseractExample)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            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)
            at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>dir
     Volume in drive C has no label.
     Volume Serial Number is 58A6-0C50
    
     Directory of C:\work\java\Tess4J\src\net\sourceforge\tess4j\example
    
    17.12.2013  20:08    <DIR>          .
    17.12.2013  20:08    <DIR>          ..
    17.12.2013  20:06               197 tess1.bat
    17.12.2013  20:08               191 tess11.bat
    26.12.2013  16:47               920 TesseractExample.class
    17.12.2013  19:44               622 TesseractExample.java
                   4 File(s)          1*930 bytes
                   2 Dir(s)  73*354*510*336 bytes free
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>
    Is the C:\work\java\Tess4J\src\net\sourceforge\tess4j\exa mple> right way to hold and execute files?

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    You need to specify the full class name including the package name with the java command.
    java the.full.package.here.Classname
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    if the .java file and compiled .class file are located in:
    Java Code:
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example
    and in code the package is:
    Java Code:
    package net.sourceforge.tess4j.example;
    then java command will be:
    Java Code:
    java net.sourceforge.tess4j.example.TesseractExample
    ?
    It gave me error:
    Java Code:
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>tess11.bat
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>java -cp .;
    ..\..\..\..\..\lib\ghost4j-0.3.1.jar;
    ..\..\..\..\..\lib\jai_imageio.jar;
    ..\..\..\..\..\lib\jna.jar;
    ..\..\..\..\..\lib\junit-4.10.jar;
    ..\..\..\..\..\dist\tess4j.jar net.sourceforge.tess4j.example.TesseractExample
    Error: Could not find or load main class net.sourceforge.tess4j.example.TesseractExample
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    The classpath needs to point to the folder that contains the folder at the beginning of the package's name: net

    The classpath + the package name = location of the class file.

    The path's might be shorter if the java command was issued in the src folder.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    I am still not getting the point. Thank you for being so patient so far with newbie like me.

    My package = net.sourceforge.tess4j.example
    so my classpath should be C:\work\java\Tess4J\src
    because under that is structure:
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\exa mple> (inside that folder is the classfile TesseractExample.java and TesseractExample.class)
    Now I try to compile inside that example folder:
    javac -cp .;c:\work\java\Tess4J\src\ TesseractExample.java
    I will get 65 errors like:
    Java Code:
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:21: error: pac
    kage net.sf.ghost4j does not exist
    import net.sf.ghost4j.*;
    ^
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\ImageIOHelper.java:364: error: c
    annot find symbol
            TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
    
            ^
      symbol:   class TIFFImageWriteParam
      location: class ImageIOHelper
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\ImageIOHelper.java:364: error: c
    annot find symbol
            TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
    
                                                     ^
      symbol:   class TIFFImageWriteParam
      location: class ImageIOHelper
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:74: error: can
    not find symbol
            Ghostscript gs = Ghostscript.getInstance();
            ^
      symbol:   class Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:74: error: can
    not find symbol
            Ghostscript gs = Ghostscript.getInstance();
                             ^
      symbol:   variable Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:94: error: can
    not find symbol
            } catch (GhostscriptException e) {
                     ^
      symbol:   class GhostscriptException
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:126: error: ca
    nnot find symbol
            Ghostscript gs = Ghostscript.getInstance();
            ^
      symbol:   class Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:126: error: ca
    nnot find symbol
            Ghostscript gs = Ghostscript.getInstance();
                             ^
      symbol:   variable Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:153: error: ca
    nnot find symbol
            } catch (GhostscriptException e) {
                     ^
      symbol:   class GhostscriptException
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:171: error: ca
    nnot find symbol
            Ghostscript gs = Ghostscript.getInstance();
            ^
      symbol:   class Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:171: error: ca
    nnot find symbol
            Ghostscript gs = Ghostscript.getInstance();
                             ^
      symbol:   variable Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:195: error: ca
    nnot find symbol
            } catch (GhostscriptException e) {
                     ^
      symbol:   class GhostscriptException
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:212: error: ca
    nnot find symbol
            Ghostscript gs = Ghostscript.getInstance();
            ^
      symbol:   class Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:212: error: ca
    nnot find symbol
            Ghostscript gs = Ghostscript.getInstance();
                             ^
      symbol:   variable Ghostscript
      location: class PdfUtilities
    c:\work\java\Tess4J\src\net\sourceforge\vietocr\PdfUtilities.java:233: error: ca
    nnot find symbol
            } catch (GhostscriptException e) {
                     ^
      symbol:   class GhostscriptException
      location: class PdfUtilities
    65 errors
    
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\example>

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    A suggestion: Start learning about packages and classpath with a simpler single folder package name instead of this very long name.
    When you get it working with a single folder then try adding some more folders.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    I managed to create my own examples within one folder successfully even when I typed there also very long name delimited with dots. But importing that Tess4J files requires using using folders correctly.

    Can you please confirm that everything is done correctly so far before I execute java command (java -cp .;..\..\..\..\..\dist\tess4j.jar net.sourceforge.tess4j.example.TesseractExample):

    script (TesseractExample.java) is located in
    C:\work\java\Tess4J\src\net\sourceforge\tess4j\exa mple>
    package line in script looks like:
    Java Code:
    package net.sourceforge.tess4j.example;
    Jar files are located under:
    C:\work\java\Tess4J\src\ (4 .jar files)
    C:\work\java\Tess4J\dist\
    (tess4j.jar)
    and compiling with command:
    javac -cp .;..\..\..\..\..\dist\tess4j.jar TesseractExample.java
    goes without errors.

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    .;..\..\..\..\..\
    That coding really looks like an easy place to make mistakes. Look at using a batch file with a variable to hold the path(s) to the folders with the jar file.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    That part is correct - I checked. When I use:
    javac -cp .;..\..\..\..\dist\tess4j.jar TesseractExample.java
    instead of
    javac -cp .;..\..\..\..\..\dist\tess4j.jar TesseractExample.java
    then it doesn't compile.

  17. #17
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    I'd use the one that works.

    Those long paths still look ugly and an easy place to make an error.
    If you don't understand my response, don't ignore it, ask a question.

  18. #18
    rothe is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    Quote Originally Posted by Norm View Post
    I'd use the one that works.

    Those long paths still look ugly and an easy place to make an error.
    Yep, those paths are ugly (funny, I have been told to put my .java file that lowest level of folder according to package name) but they are correct. So that can't be problem why I cannot run java command.

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Tesseract - Javac fails, probaly cannot find right jar files

    As I said before, start with a single folder path, get it to work, add a folder, get it to work, etc.
    Stop adding folders when it stops working. Backup and try again.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: 10-21-2013, 11:29 AM
  2. Replies: 0
    Last Post: 07-20-2012, 07:34 PM
  3. can not find java and javac files in dir
    By Gerard in forum New To Java
    Replies: 18
    Last Post: 01-25-2012, 12:27 AM
  4. javac - cannot find symbol
    By BigBear in forum New To Java
    Replies: 3
    Last Post: 03-05-2010, 12:35 PM
  5. javac can't find javax.ejb...
    By qrac in forum New To Java
    Replies: 3
    Last Post: 07-30-2009, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •