Tess4j unsatisfied link error on mac OS X - java

Hey i am trying to use tess4j for tesseract and having this issue for eclipse on mac osx .
My tesseract is working fine from terminal but trying to run tess4j through tesseract throws me an error .
java.lang.UnsatisfiedLinkError: Unable to load library 'tesseract': Native library (darwin/libtesseract.dylib)
i do have tessetact dylib and its named libtesseract.dylib in my opt/local/lib which i installed using macport .
Thanks for your help

I know it's an old post. I had this problem too recently when I tried to use Tess4J. However, I managed to find a way around it. I've written a post about it http://www.microshell.com/programming/java/performing-optical-character-recognition-in-java/
In short, the problem is because tess4j-2.0.0.jar doesn't include MacOS library. So I just modified the maven cached jar on mine by doing these steps:
cd /Users/user/.m2/repository/net/sourceforge/tess4j/tess4j/2.0.0 (adjust the directory where your tess4j JAR file resides)
mkdir darwin
jar uf tess4j-2.0.0.jar darwin
cp /opt/local/lib/libtesseract.3.dylib darwin/libtesseract.dylib
jar uf tess4j-2.0.0.jar darwin/libtesseract.dylib
jar tf tess4j-2.0.0.jar (to verify that the file is included)
I was then able to run my Java program after I modify the tess4j-2.0.0.jar file. Below is my MacOS version.
user#laptop:~$ uname -a
Darwin Maresas-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64

I had a very similar issue with Ghost4j, i.e.
InvocationTargetException: Unable to load library 'gs': Native library (darwin/libgs.dylib) not found in resource path
Instead of modifying jar files, point jna to the appropriate lib path by setting jna.library.path. In Eclipse, you need to set the system property in run configurations - SO answer for this here - https://stackoverflow.com/a/862405/2163229
If you're using Maven exec:
mvn -Djna.library.path=/opt/local/lib/ exec:java -Dexec.mainClass="foo.bar.NativeThingy"
or
export MAVEN_OPTS="-Djna.library.path=/opt/local/lib/" && mvn exec:java -Dexec.mainClass="foo.bar.NativeThingy"
Obviously, set the path to wherever your libs are installed. In my case, I ran $ locate libgs.dylib and found the above path.
References:
https://jna.java.net/javadoc/com/sun/jna/NativeLibrary.html

You need install the tesseract lib on your Mac.
brew install tesseract --with-all-languages

#maresa after a few years your comment helped me, thanks a lot :) A bit different paths, maybe it'll help someone:
cd /Users/username/.m2/repository/net/sourceforge/tess4j/tess4j/4.5.4/
mkdir darwin
jar uf tess4j-4.5.4.jar darwin/
brew info tesseract (here you can find path to libtesseract.4.dylib)
cp /usr/local/Cellar/tesseract/4.1.1/lib/libtesseract.4.dylib darwin/libtesseract.dylib
jar uf tess4j-4.5.4.jar darwin/libtesseract.dylib
jar tf tess4j-4.5.4.jar
MacOS Catalina - 10.15.3

Make sure you use libtesseract.dylib of Tesseract 3.02 version. Check out this post on Tesseract Forum.

This is exactly what I was after today, so thanks for the Q&A above. As one additional step beyond what maresa mentioned, I ran into this error after fixing the one you asked about:
java.lang.UnsatisfiedLinkError: dlopen(/var/folders/sq/rh89_ntd7jqdlv9__25zj9dr0000gp/T/jna--913086793/jna8800789057827590119.tmp, 9): Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /usr/local/lib/liblept.4.dylib
Reason: image not found
So to fix this I needed to set up a symlink for libjpeg.8.dylib:
ln -s /usr/local/Cellar/jpeg/8d/lib/libjpeg.8.dylib /usr/local/lib/libjpeg.8.dylib
Not sure if there is a way to do this without the symlink (i.e. package it in the jar), but I hope this helps anyone else who is looking at this post.

Based on maresa's answer above, which works perfectly, I wrote a library that will make it easy to patch the tess4j.jar file with the appropriate C library from tesseract. You can get it here.

Related

Encountered error setting up plugins for Minecraft Nukkitx server on Raspberry Pi

RPI 2B, running Debian/Jessie, with java version 1.8.0_65.
Downloaded latest nukkitx from https://nukkitx.com.
Followed installation instructions at https://github.com/IntellectualCrafters/PlotSquared/wiki/Installation.
Plugins I have installed:
Plot Squared 18.07.21-aaa7088-2022
FastAsyncWorldEdit 18.07.21-a00345f-1159-20.4.0
DbLib 0.2.3
Error I am encountering:
java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open(Ljava/lang/String;I)V
Stack trace: https://pastebin.com/C3DrUm0Q.
Full server log: https://pastebin.com/2iuvQmbC.
As you can see, it says that PlotSquared has been loaded, but none of the plot commands are available. It just says unknown command when I type it. I have tried several different versions of all of the plugins, and a couple previous versions of nukkitx, all have the same problem. I'm thinking its something about my device, but I'm still pretty new to Linux and am not sure what to try next. Any suggestions would be amazing!
EDIT: I download the driver from https://github.com/xerial/sqlite-jdbc, and added it to the class path when calling the nukkitx jar to start the server. This didn't fix the problem. Here is the .sh file to start the nukkit jar:
#!/bin/sh
echo $USER
java -Xms1G -Xmx1G -cp ".;sqlite-jdbc-3.23.1.jar" -jar nukkit-1.0-SNAPSHOT.jar
I figured it out! For whatever reason, the JbLib sqlite driver apparently wasn't working. The solution was to remove JbLib (jar and folder) from the plugins folder, change the start.sh file (which I created according to the installation instructions) to use a classpath command instead of a jar command, add the xerial sqlite driver to the class path, and specify the Main Nukkit class to execute, like so:
java -classpath nukkit-1.0-SNAPSHOT.jar:sqlite-jdbc-3.23.1.jar cn.nukkit.Nukkit

Installing Chronix

I'm trying to install Chronix on my hadoop cluster(Raspbian) (http://chronix.io/) so i followed the tutorial (in Quickstart) but when i have to $ java -jar chronix-timeseries-exploration-0.2.jar
I got `ERROR:
Could not find or load main Class de.qaware.chronix.examples.exploration.ui.MainRunner`
So I've read lots of things about this, how to change classpath , ... but the thing is that opposite to all of the people who were asking questions, I don't know where the file is if not in the folder : /home/hduser/chronixShowcase so I don't know where to set the PATH I tried with path at:
/home,
/home/user
/home/user/chronixShowcase
/chronixShowcase/chronix-solr-6.0.1/
/chronixShowcase/chronix-solr-6.0.1/bin
with CLASSPATH=path export CLASSPATH
It may have to be downloaded but this file is not on Github (only this kind: chronix-importer/release/data/qaware-jenkins/20160226/jenkins_jenkins-jolokia_jenkins-jmx_qaware-jenkins_2016.02.27_00.00.00.csv.gz)
Do you have any suggestion to find the main class or export the right PATH or if it comes from elsewhere? I would be really happy if you could help me!
According to the quickstart it looks like you download it from GitHub
wget https://github.com/ChronixDB/chronix.examples/releases/download/0.2/chronix-timeseries-exploration-0.2.jar
From: https://github.com/ChronixDB/chronix.examples/blob/master/chronix-timeseries-exploration/README.md
JavaFX is not included in OpenJDK on Linux. As a result the following error occurs when starting the application with OpenJDK.
Solution
Use Oracle JDK that includes JavaFX
Install the missing JavaFX package for OpenJDK, e.g for Ubuntu:
Try:
sudo apt-get install openjfx

Eclipse Error for GLPK library: The dynamic link library for GLPK for Java could not beloaded

I have a java program in which a use the GLPK Solver. The error that i receive when i run it on eclipse is the following:
The dynamic link library for GLPK for Java could not beloaded.
Consider using
java -Djava.library.path=
The current value of system property java.library.path is:
/Users/maria/Documents/solver_library/GLPK/w64
I had the same problem on my old windows computer and i solved it doing the following:
1. Adding in the Java Build Path->Libraries the glpk-java.jar file
2.Adding as the Native library location of the above jar the corresponding path (C:\ProgramFiles\solver_library\GLPK\w64
3. adding in the PATH environment variable the above path.
I am doing exactly the same things on my new MAC OS X computer but still receiving the above error. I did with exactly the same way the steps 1 and 2 above and also I modified through the terminal the PATH system variable. This now is:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/maria/Documents/solver_library/GLPK/w64
Could you please tell me if you have any idea of how to solve this? I am a new Mac user so i don't know many things.
Thanks in advance!
Here's what I did to make it work on OS X.
Install glpk.
I used for this homebrew
$ brew install glpk
$ brew install swig // this package we well need for glpk for java
Install glpk for java http://sourceforge.net/projects/glpk-java/files/glpk-java/
Unzip the archive with:
$tar -xzf glpk-java-1.0.37.tar.gz
$cd glpk-java-1.0.37
Configure with:
$./configure \
CPPFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers \
SWIGFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers
Make and install with:
$make
$make check
$make install
Now in swig dir you should have 3 jars:
glpk-java.jar, glpk-java-sources.jar, glpk-java-javadoc.jar and the .lib folder (hidden).
For compiling you need to put glpk-java.jar in your classpath and specify javac option -Djava.library.path=/YOUR_PATH/libglpk-java-1.0.37/swig/.libs

java.lang.UnsatisfiedLinkError: no xuggle-xuggler in java.library.path

I'm using Ubuntu 11.04 and Eclipse. I installed Xuggler succesfully, I've checked the environment variables and everything related with linux in their FAQ: http://wiki.xuggle.comFrequently_Asked_Questions#What.27s_up_with_java.lang.UnsatisfiedLinkError.3F
I also set up Eclipse according to their tutorial:
http://xuggle.wordpress.com/2009/01/23/how-to-write-your-first-xuggler-application-in-eclipse/
Whenever I try running any code which uses Xuggler I get the following error:
2011-09-14 14:17:30,093 [main] ERROR com.xuggle.ferry.JNILibraryLoader - Could not load library: xuggle-xuggler; version: 3; Visit http://www.xuggle.com/xuggler/faq/ to find common solutions to this problem
Exception in thread "main" java.lang.UnsatisfiedLinkError: no xuggle-xuggler in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at com.xuggle.ferry.JNILibraryLoader.loadLibrary0(JNILibraryLoader.java:265)
at com.xuggle.ferry.JNILibraryLoader.loadLibrary(JNILibraryLoader.java:168)
at com.xuggle.xuggler.XugglerJNI.<clinit>(XugglerJNI.java:19)
at com.xuggle.xuggler.IContainer.<clinit>(IContainer.java:1457)
at com.xuggle.mediatool.MediaReader.<init>(MediaReader.java:137)
at com.xuggle.mediatool.ToolFactory.makeReader(ToolFactory.java:77)
at recode.main(recode.java:16)
So, how to solve this?
I got the answer/solution from the xuggler-users google group, credits to Navin Bhutada:
solve it by including the Xuggle variables before runing the netbeans like this:
export XUGGLE_HOME=/home/xyzuser/xuggler
export PATH=$XUGGLE_HOME/lib:$XUGGLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$XUGGLE_HOME/lib:$LD_LIBRARY_PATH
/usr/share/netbeans/6.9/bin/./netbeans"
I use eclipse, so I just changed that last line, running eclipse from its folder through the command line and everything worked just fine.
Note: If I export the variables and try opening eclipse from a shortcut on my desktop it doesn't work. The shortcut point to the same file I ran from the command line
TLDR:
export variables you got after installing
run Eclipse from the terminal.
You just download correct Xuggle from this page based on ur os:
http://xuggle.googlecode.com/svn/trunk/repo/share/java/xuggle/xuggle-xuggler/5.2/
And then extract the lib files to project home folder.
I've found that even though I may have my environment variables set correctly, explicitly including the Xuggler install dir in the java.library.path when executing saves me from that problem.
i.e. java -Djava.library.path="$XUGGLE_HOME" myExecutable
Cause Could be un-availability of dependency jars or version conflicts.
Adding the following jars in the classpath worked fine for me:
xuggle-xuggler-5.4.jar
slf4j-api-1.6.4.jar
logback-core-1.0.0.jar
logback-classic-1.0.0.jar
Note: Add them in the library folder using "Add jar/Folder" Option in netbeans.

Having Problems Getting FreeTTS and JSAPI Working

First off I'm on Ubuntu linux if that matters.
I have a simple project idea based off of FreeTTS and the JSAPI (Java Speech API)
I've downloaded and unpacked FreeTTS and run their build script. Then tried compiling my code linking several jar's required in the lib directory into the class path like this:
javac -cp /home/travis/Desktop/freetts-1.2/lib/jsapi.jar:/home/travis/Desktop/freetts-1.2/lib/freetts.jar HelloUnleashedReader.java
Which then compiles to java bytecode just fine.
However when I run:
java HelloUnleashedReader
I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/speech/EngineModeDesc
Any help on this issue would be greatly appreciated as there are many sites around the net discussing problems with getting it to work but not many that discuss their solution.
I see that you are using Ubuntu. You must agree to the binary license before you can use jsapi.jar. You agree to this license in the process of unpacking it. To unpack jsapi.jar in Ubuntu you would type the following:
cd ~/Desktop/freetts-1.2/lib
chmod +x ./jsapi.sh
./jsapi.sh
if you receive a message like
"./jsapi.sh: 1428: uudecode: not found"
then install uudecode with
sudo apt-get install sharutils
and try again
You need to add the jsapi.jar into your classpath. The jsapi.jar can be unpacked by running lib/jsapi.exe inside the freetts installation directory.
I got this error despite I had jsapi.jar on classpath.
java -cp `ls *.jar | awk '{ORS=":";print}'` -jar WebStartClock.jar
What helped me was specifying the main class explicitely:
java -cp `ls *.jar | awk '{ORS=":";print}'` JSAPIClock
Probably something wrong in the JAR metadata or so.

Categories