Java Unable to load libary 'tesseract' not found in resource path [duplicate] - java

I've had tesseract and Tess4J running on my MBP for a while now. Today I started to migrate my app to the server and started installing everything on the server. Prior to running Tess4J in tomcat I tried to run a simple java program to make sure everything is fine and dandy. It's not...
I'm on a centOS 64bit server
I've installed tesseract and its working fine - tesseract myimage.jpg mytext produces data
However, running my simple class that useses Tess4j produces this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to
load library 'tesseract': libtesseract.so: cannot open shared object
file: No such file or directory
What I've done so far
I've ran sudo ldconfig after installing tesseract
I've search for libtesseract.so and its found in /usr/local/lib/libtesseract.so
Folder on server contains these files:
myimge.png
ghost4j-0.3.1.jar
jai_imageio.jar
jna.jar
maslab.jar
pngj.jar
tess4j.jar
TesseractExample.class
TesseractExample.java
tesseract -v produces:
tesseract -v
tesseract 3.02.02
leptonica-1.69
libjpeg 6b : libpng 1.2.49 : libtiff 3.9.4 : zlib 1.2.3
Question
How can I make Tess4J aware that libtesseract.so does exist?enter code here

I had this problem too.
Did you run the following after installing tesseract:
sudo ldconfig
That fixed it for me.

You must set LD_LIBRARY_PATH environment variable to the path where libtesseract.so is.
export LD_LIBRARY_PATH=/usr/local/lib

It is necessary to define the variable jna.platform.library.path. For instance:
-Djna.platform.library.path=/usr/local/lib/

Maybe it is a 32 bit library .so installed.

Related

pyspark not able to start

I am having Windows 8.1 operating system. I installed apache spark and then, installed Java JDK. I am using git bash in windows. I am having below setting in my .bash_profile of git bash.
export SPARK_HOME="/c/tools/spark-2.3.1-bin-hadoop2.7"
export PATH="$SPARK_HOME/bin:$PATH"
export JAVA_HOME="/c/Program Files (x86)/Java/jdk1.8.0_181/"
When I try to call pyspark, I am getting error as given below.
/c/tools/spark-2.3.1-bin-hadoop2.7/bin/pyspark: line 45: python:
command not found Error: Could not find or load main class
org.apache.spark.launcher.Main
I tried running spark-shell in the path "/c/tools/spark-2.3.1-bin-hadoop2.7/bin/". Still getting the same error.
Please help me in making pyspark running in my machine.
I was finally able to make pyspark work in Windows, by following the steps in the blog
http://nishutayaltech.blogspot.com/2015/04/how-to-run-apache-spark-on-windows7-in.html
I had to install few more tools and set environment variables and finally make it working.

java tesseract error in linux "Unable to load library 'tesseract': libtesseract.so"

I am using tess4J ocr library in eclipse and is working fine in my windows. But when i want to run that java program in linux it is giving an error "Unable to load library 'tesseract': libtesseract.so: cannot open shared object file: No such file or directory".
I dont have any permissions on linux to install the tesseract or any other software . Just i can use the jar files and run the java program by calling the shell script.Please help me on this . As I am thinking my problem will be solved by getting libtesseract.so file or help me how to get libtesseract.so in windows so that i will use that in linux . Please help and thank in advance
It is enough to install Tesseract for Linux using command:
sudo apt-get install tesseract-ocr
now you can check tesseract version, using command:
tesseract -v
Please note, that for Tesseract 3.03 you can use Tess4j version 2.0.
Another version may give you errors because of incompatibility.
You can get more info about different version compatibility in Change Log, or here.
In My case (centos) I copied all the files (having lept or teesseract keyword in file name) from folder
/usr/local/lib
to folder
/usr/lib64
and it solved my problem
On Linux, Tess4J calls on Tesseract native library libtesseract.so to work. If you can't build or install Tesseract on Linux, you're in tough luck. Maybe if you can cross-compile to a .so on Windows using Cygwin or Mingw.
You have to set -Djava.library.path so the file can be found or tweak your standard library path to include the location of the .so in .bashrc by extending system's LD_LIBRARY_PATH
You need to install without root and specify the path of your libtesseract.so
Install elsewhere / without root
Tesseract can be configured to install anywhere, which makes it possible to install it without root access.
To install it in $HOME/local:
./autogen.sh
./configure --prefix=$HOME/local/
make install
To install it in $HOME/local using Leptonica libraries also installed in $HOME/local:
./autogen.sh
LIBLEPT_HEADERSDIR=$HOME/local/include
./configure \ --prefix=$HOME/local/ --with-extra-libraries=$HOME/local/lib
make install
I also had same problem. Tesseract libraries was aslo present under /usr/local/lib directory.Still I was getting this error. Actually this is linking problem. so you have to provide the /usr/local/lib path to the resolver path in the /etc/ld.so.conf.d/libc.conf file. make entry of path in this file or you can create any new conf file in the same dir.

Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory

I have installed ghostscript of 64 bit on my 64 bit linux machine. I am using ghost4j-0.5.0.jar to convert pdf files to tiff files. I have written a java program which will convert pdf files to tiff files. This is working perfectly fine on Windows but when i thought of moving this to linux machine i am getting the below error.
"Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory"
I checked lib folder and could not find libgs.so file in the lib folder. I am not sure where to get that file.
Can anyone please help me on this ?
I feel a little guilty posting this here since it is probably better served on ServerFault or one of the Linux boards and the question is over 6 months old but I had been banging my head against the wall all day and finally have found a solution to this problem and I figured someone else might benefit from this down the road.
Systems: Windows 7 and CentOS 6.5
Using: Ghostscript 9.14
A little backstory:
Like the OP I had been running a ghostscript program on Windows to convert PDFs to a series of images. This worked fine until I needed to switch over to Linux and run the program and about 5% of the PDFs I needed to convert came up with error cannot decode code stream. I realized that I was using a newer version of ghostscript on Windows. (9.14 on Windows compared to 8.70 on CentOS due to installing through yum).
I removed the old version with yum remove ghostscript. Next, I found the easiest way to install the newest version of Ghostscript is download from here and compile. Since I removed the previous version of ghostscript with yum I had to update the link in usr/bin to point to usr/local/bin/gs with ln -s /usr/local/bin/gs /usr/bin/gs. With everything in place, so I thought, I attempted to run my program and then bam, error!
Solving the problem:
So now I was getting the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory
I came across a post here that said to get the necessary libgs.so I needed to go back and rebuild the source as a shared library with the command make so. I did so and then I took the libgs.so.9.14 file under sobin directory in the ghostscript folder and copied it to /usr/lib. Under that directory I made a symbolic link to libgs.so using the command ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so.
Once that was done I needed to update my ld_library_path but found when I did so the change wasn't global so I found a Unix & Linux post on how to set the global lib path. Basically to do so you need to go to add a .conf file in /etc/ld.so.conf.d/ with the path to the file. I did so using vi /etc/ld.so.conf.d/libgs.conf and added /usr/lib/libgs.so to the file. Lastly I ran ldconfig so save the changes.
TLDR:
Download the latest version of Ghostscript from source: wget http://downloads.ghostscript.com/public/ghostscript-9.14.tar.gz
Unpack the tar: tar -xzf ghostscript-9.14.tar.gz
cd ghostscript-9.14
./configure
make <-- You might be able to skip and go to make so, I did it in this order so I will leave it like this.
make install
make so
If you removed a previous version with yum ln -s /usr/local/bin/gs /usr/bin/gs
cp ghostscript-9.14/sobin/libgs.so.9.14 /usr/lib
ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so
vi /etc/ld.so.conf.d/libgs.conf
In the new libgs.conf file: /usr/lib/libgs.so and save with esc, :, wq.
ldconfig and done.
Run your conversion program.
Hopefully this helped and wasn't too confusing. I'm not a linux expert (yet) so I may be doing a little more work than necessary with the above commands but I wanted to be thorough.
I just had this issue on a linux VM. I was able to solve it by installing ghostscript on the system. I just used the command:
sudo yum install ghostscript
Hope that helps!
make soinstall will create required libs along with executables as mentioned in https://www.ghostscript.com/doc/current/Install.htm#Shared_object

java.lang.RuntimeException: Registry initialization file not found

When I work with JAI from the Eclipse (all the classes specified)
it works very fine, but when I bundle everything in a jar and make a shell script file from that and try to run that script I have a problem with javax.media.jai.OperationRegistry
looking for a initialization file.
Has anyone else seen this problem?
Exception:
java.lang.RuntimeException: Registry initialization file not found.
at
javax.media.jai.OperationRegistry.initializeRegistry(OperationRegistry.java:365)
at javax.media.jai.JAI.(JAI.java:566)
There is something on this page but I was not able to understand.
Any Help?
So the problem is that the JAI jar exported with the Java application do not work on the Linux. We have to explicitly install JAI on the Linux machine for the installed Java application to use.
The one solution that we found out is we exported our Java Application into a jar file and created a installation script, which when run on the Linux machine install the JAI first and after that it install our application.
So this is a one time installation process while installing the application on any fresh Linux machine.

JMagick setup problems with Eclipse in OS X - UnsatisfiedLinkError: no JMagick in java.library.path

I am having some trouble setting up my environment in Eclipse for ImageMagick via JMagick in OS X. I have no problems using the ImageMagick command line tools (display, convert, etc.) after installing, but am unable to set up JMagick with a Java project in Eclipse.
Steps taken:
Downloaded JMagick 6.4.0
Generated jar and libs through make process in the INSTALL document
Copied libJMagick.so and libJMagick-6.4.0.so from lib to /usr/lib/java
Added JMagick.jar to build path
Linked /usr/lib/java directory to JMagick.jar native source, recommended in the solution posted by trigoman at the following url: JMagick Error when trying to load a file - UnsatisfiedLink
Created sample class that accesses JMagick and attempted to run in Eclipse. Exception reported:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no JMagick
in java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758) at
java.lang.Runtime.loadLibrary0(Runtime.java:823) at
java.lang.System.loadLibrary(System.java:1045) at
example.ImageRender.main(ImageRender.java:10)
Does anyone have any ideas what might be the underlying problem is?
edit: see my comment below about using im4java instead of JMagick.
I was having the same problem, but just got it working by following these sparse instructions:
http://wesleyli.blog.com/2011/09/01/install-jmagick-on-mac/
But note there's a couple typos; looks like Lion auto-correct problems.
So what I did was:
svn co https://jmagick.svn.sourceforge.net/svnroot/jmagick jmagick
cd jmagick/trunk
./configure --with-java-home=/System/Library/Frameworks/JavaVM.framework/Versions/Current --with-magick-home=/usr/local/jmagick
sudo make all & sudo make install
sudo ln -s /usr/local/lib/libJMagick-6.5.7.so /Library/Java/Extensions/libJMagick.jnilib
And now it works for me. :)

Categories

Resources