I am working on an application in which I am using Tesseract for OCR.
My code is working absolutely fine in windows 32 bit system.
But when I try to run the same code in 64 bit machine using the 32 bit .dll files, the code is running but then the code is not giving the accurate results.
So I am running it in 64 bit machine using the 64 bit .dll files.
Now when I tried to run the same program, I got the following error in Console(Eclipse Kepler).
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: %1 is not a
valid Win32 application.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:38)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:293)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:227)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:176)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:159)
I have downloaded the 64 bit .dll files (https://github.com/charlesw/tesseract/tree/master/src/lib/TesseractOcr/x64) compatible with 64 bit system but still i am getting the same error.
I am using GhostScript v-8.71 on 64 bit machine. I have installed this in both Program Files and Program Files(x86). I have also set the environment variables accordingly.But still not working.
Please please provide me with some solution!
Tess4J only currently supports 32-bit JVM
This is the creator, nguyenq, responding to a similar issue on a sourceforge forum.
Similarly, in the tutorial it points out that only 32-bit DLL's are included in the distro.
To run with a JVM 64-bit, you'll need to use Tesseract and Leptonica 64-bit DLLs.
One solution: Tell your IDEto use a 32-bit JVM instead.
-- downside is that you may be mixing 32 bit and 64 bit environments, in a complicated app or env this could be odd... (I don't think it's too bad, but might be a pain in your IDE)
In an update found here, it seems you can find DLL's for 64-bit Java here, as part of the Tesseract wrapper for .NET (oddly enough). However, I haven't tried out those 64-bit DDL's yet and in the sourceforge link, it says they depend on the Visual C++ Redistributable for VS2012 or Visual C++ Redistributable for VS2013 ... which sucks....
I'll update this post if I figure out a cleaner solution.
UPDATE
Note that I did this working with Amazon Web Services instances.
I was able to get Tess4J to work on a 64-bit Ubuntu 14.04. It was actually very simple once I gave up on my Red Hat distro and went to Ubuntu.
sudo apt-get install tesseract-ocr will get tesseract set up completely. You can check by typing tesseract -v. I also needed GhostScript because I was working with PDF's. sudo apt-get install ghostscript again got everything set up. Verify with gs -v.
Now in your Java app, all you need to include are the JAR's from Tess4J's download in your path -- jna-4.1.0j.ar, jai_imageio.jar, tess4j.jar, and ghost4j-0.5.1.jar if you are working with PDF.
In your Java app, you need to set the data path so your Tesseract instance knows where tesseract is installed. Even while I had the environment variable set, it never worked for me. I needed to explicitly set the data path like so:
Tesseract tessInstance = Tesseract.getInstance();
tessInstance.setDatapath(System.getenv("TESSDATA_PREFIX"));
ImageIO.scanForPlugins(); // make sure it knows about GhostScript, to work with PDFs
String result = tessInstance.doOCR(myFile);
Be sure that setDatapath() sets to the parent folder of the tessdata folder of your tesseract installation (on my Ubuntu this was /usr/share/tesseract-ocr/`).
That was all I needed. No worrying about DLL's in class path.
tl;dr:
Use up-to-date Ubuntu
sudo apt-get tesseract-ocr
sudo apt-get ghostscript if working with PDF
include proper Tess4J JAR's (jna-4.1.0j.ar, jai_imageio.jar, tess4j.jar, and ghost4j-0.5.1.jar if you are working with PDF)
call tess.setDataPath() to point to your tesseract installation (/usr/share/tesseract-ocr/ for my Ubuntu 14.04)
ImageIO.scanForPlugins() if using GhostScript
That's it. You are good to go call tess.doOCR(MyFile) happily
Related
I have a jar file 'myApp.jar' that I need to run through command line. When I run the jar on linux server it working perfect. However, when I tried to the same jar on mac terminal I am getting this error message:
Exception in thread "main" java.lang.UnsatisfiedLinkError: while loading kognac-core: Stream closed
at karmaresearch.vlog.VLog.loadLibrary(VLog.java:72)
at karmaresearch.vlog.VLog.<clinit>(VLog.java:22)
at org.semanticweb.rulewerk.reasoner.vlog.VLogReasoner.<init>(VLogReasoner.java:82)
at org.semanticweb.rulewerk.client.picocli.MyApp.someMethod(MyApp.java:150)
at org.semanticweb.rulewerk.client.picocli.MyApp.main(MyApp.java:110)
The command that I used to run the jar is:
java -jar myApp.java
The jar file is compiled and created by javaSE-1.8 through Eclipse on Mac.
The java version of Linux server is openjdk version "1.8.0_292"
The java versions on Mac are 3: Java SE 11.0.1(default version) , 1.8.0_202, 1.8.0_201 by these commands:
/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/bin/java -jar myApp.java
/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/bin/java -jar myApp.java
I tried to run the jar file on mac with all 3 java versions, but still getting the same error above.
How could I resolve this error on Mac terminal?
The problem isn't related to your app or how you run it.
Your app uses the karmaresearch project which I'm not familiar with (possibly, that's your own code, that you / your team wrote?) and this code attempts to load a so-called native library: These are libraries compiled straight for the OS/architecture your JVM is running on top of.
These take the form of a .jnilib file on mac, .dll on windows, and .so on linux and other posix-based OSes.
Native libraries are incredibly convoluted to ship: You need 1 such file for each combination of OS and underlying architecture. So, these days, you'd need at a minimum to make a reasonable claim that you're 'portable':
Mac AAarch64
Mac x84
Windows x64
Linux AArch64
Linux x64
Linux x32
BSD x64
and that's just a bare bones minimum.
These files cannot be inside the jar when you load them. The usual procedure is to obtain a location you can write to and load code out of (tricky), unpack the right file for the host OS to this folder, and then loadLibrary it. This is all very complicated. In general, either [A] you wrote karmaresearch and you need to think long and hard about using native libraries first, and if you truly need it, follow a tutorial, or [B] it's not your code, in which case you can't run this on a mac, at all, and there's nothing you can do about that, other than contact the makers of this library and ask them to add support for this.
I am getting the following message immediately after trying to run the executable file.
Java Runtime Environment not found.
I have installed jdk and jre and already set the path for both and able to run any class file with command prompt.
Unfortunately, i am not using Netbeans or Eclipse.
please someone help
Thanks in advance.
I found jar2exe website support that include install 32 bit jre for 32 bit OS and 64 bit jre for 64 bit OS. The best solution is reinstall correct version of Java and choose offline installer (since online installer mostly install 32 bit before, but I don't sure is smart enough to detect 32 bit or 64bit now).
(I'm sorry that I don't gain enough reputation to post on comments)
You need an appropriate jre installed that is the same with your Jar2Exe (on step 6 during Exe creation). If you're check "Create 64 bits executive" on those step you'll need 64 bit jre, but if you unchecked it then you need 32 bit jre.
I faced this issue many a times while working with a new setup or after a Java upgrade. Logical solution for this? Except replacing jvm.dll file?
Never realized, but the solution is quite easy. As per my understanding:
Observations:
If you are using a 64bit Windows system, then you would notice that there are two Program Files folder in your C:/ Drive.
That means, Program Files, which contains 64-bit programs and applications, and. Program Files (x86), which contains 32-bit programs and applications.
Now if you are using a 64bit system, then it is easy and recommended that you use softwares as well of 64bit. So your Path in System variables should contain the path details of your Java 64bit.
Now coming back to the original problem, here if we are on 64Bit Microsoft Windows system and wish to use 64bit Software (Eclipse for example), then let us set the Path for the 64bit Java.
Then make a simple test on command prompt.
-cmd
-java -version
Shows the 64bit Java VM is set to path.
Now Open your Eclipse and it do not show the Error.
Always remember that we should use:
64 bit OS
64 bit Java (with Path set for 64 bit Java)
64 bit Eclipse.
Hello im trying to use in a Project a dll generated with JNI.
i generated a 64 Bit dll but my project says %1 is not a valid win32 application
So i decided to generate a new DLL, but this time 32 Bit. I changed the Settings in my Visual Studio like i found i other posts, Configuration to Win32 and Target Machine to MachineX86.
this all works fine but when i try to launch the project with this DLL i get the same error. I checked the DLL with Dependency Walker and found out the DLL is 32Bit, but the included DLL's are 64 Bit.
So you guys are my last hope. Do you have any ideas ?
Notes: i can't change to Linux atm.
Visual Studio 2012
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
just read it but i already found my error, the problem was that eclipses changes it's installed JRE's when you switch workspace.
so in my testprogramm where i developed my 64bit libary worked. but not in the real project, where the installed JRE was a different one.
so if anyone has the same problem don't forget to check this
Please check your system PATH. Windows will attempt to load the first DLL it finds that matches the DLL's name. Windows doesn't check if the DLL is 32 or 64-bit, it will attempt to load it.
If you built a 32-bit DLL, then you're responsible for making sure that any dependent DLL is also 32-bit, and that Windows finds those 32-bit DLL's first.
I have a Problem :D im working on a self generated DLL with JNI.
I have generated the DLL with Visual Studio 2013, for 64Bit machines. I have already checked with Dependency Walker if my DLL is really 64 Bit, and it is. Then i tried to use the DLL in my Java source (Eclipse Version: Luna Service Release 1 (4.4.1) Java Version 1.7.0_71-b14 64 Bit Version).
When i run my Java Programm i get the errormessage Can't load IA 32-bit .dll on a AMD 64-bit platform in this line.
static
{
System.loadLibrary("iomemjava");
}
I have already spend 2 days in this problems and searched stackoverflow and some other forums. I'm really out of Ideas what could possibly be wrong.
So far and in the hope you guys and girls can help
Martin
Java uses the system property java.library.path as the path to find native libraries. When you start your application, define this property on the command line with the -D option and make it point to the directory that contains the DLL. For example:
C:\MyProject> java -Djava.library.path=C:\MyProject\nativelib com.mypackage.MyProgram
where C:\MyProject\nativelib is the directory that contains the DLL you want to use.
go to the link http://www.apache.org/dist/tomcat/tomcat-connectors/native/
find the latest one
download tomcat-native-XXX-win32-bin.zip
open the zip file. find the tcnative-1.dll under X64 folder
finally, replace the .dll in the tomcat bin with the .dll in the zip file