Tesseract For Java setting Tessdata_Prefix for executable jar
<p>The ultimate goal of this project is to take the jar and put it in a directory where it uses tesseract and outputs a results directory and the output txt file. I am having some issues with tesseract, though. 
I am working with tess4j in Java with Maven and I want to make my code into an executable jar. The project works fine as a desktop app but whenever i try to run using <code>java -jar fileName.jar</code>(after exporting to a jar) it gives me the error</p>

<pre><code>Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory
Failed loading language 'eng'
...
</code></pre>

<p>I looked online and couldnt really find out how to set up tesseract for a jar and get the paths right. Now I use maven and have the Tesseract dependency in my pom file (tess4j -v 3.0) and I have the tessdata in my project.</p>

<p>I am fairly new to maven and jar files and have never used tesseract before, but as far as i can tell from the internet I set it up correctly. </p>

<p>Does anyone know how to make tess4j point to the tessdata directory in my project and have a dynamic path so i can move use it on multiple computers and places?</p>

<p>This is how I call Tesseract</p>

<pre><code>    Tesseract instance = new Tesseract();
    instance.setDatapath("src/main/resources");
    String result = instance.doOCR(imageFile);
    String fileName = imageFile.getName().replace(".jpg", "");
    System.out.println("Parsed Image " + fileName);
    return result;
</code></pre>

<p><strong>EDIT</strong></p>

<p>This is how I tried to set the environment variable TESSDATA_PREFIX in my code</p>

<pre><code>String dir = System.getProperty("user.dir");
System.out.println("current dir = " + dir);
ProcessBuilder pb = new ProcessBuilder("CMD", "/C", "SET");
Map&lt;String, String&gt; env = pb.environment();
env.put("TESSDATA_PREFIX", dir + "\\tessdata");
Process p = pb.start();
</code></pre>

<p>but this had no discernible effect. I still got the same error</p>

<p><strong>EDIT 2</strong></p>

<p>According to the error message I need to set it to the parent dir of the tessdata, I also tried this to no avail</p>

<p><strong>EDIT 3</strong></p>

<p>After a ton of searching and trying to fix it, I am not sure it is even possible. The doOcr method in tesseract takes in a buffered image or File, which would be alright if my images weren't dynamic so I cant really store them in the jar. Not to mention the fact that the TESSDATA_PREFIX still wont set. If anyone has any ideas i am all ears still and I will keep looking for a solution but im not sure it will work at all</p>