Cant load mecab in java windows - java

I'm trying to use mecab library in java on windows. I've installed a prebuilt mecab library for windows. When I try to load it like
try{
System.loadLibrary("libmecab");
}catch(Exception e){
// print stack trace
}
it throws a following error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.chasen.mecab.MeCabJNI.new_Tagger__SWIG_0(Ljava/lang/String;)J
at org.chasen.mecab.MeCabJNI.new_Tagger__SWIG_0(Native Method)
at org.chasen.mecab.Tagger.<init>(Tagger.java:140)
I've added mecab on library path
-Djava.library.path="c:/mecab/bin"
I can access Mecab from windows command prompt. Has anybody faced a similar problem and resolved the issue? Any help here is appreciated.

Related

Phantom UnsatisfiedLinkError (openCV + JAVA) appears in console but not in IDE

There is an issue running openCV 3.1(Also tried with 3.0) in Windows7 x64 from console.
Sample code is this one:
package com.company;
import org.opencv.core.Core;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
// write your code here
System.out.println("Entering Main");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("Creating Mat");
new Mat();
System.out.println("Finished successfully");
}
}
I can run this project in IDEA IDE without any problems. Full output:
"C:\Program Files\Java\jdk1.8.0_102\bin\java" -Dvisualvm.id=11658625891829 -Djava.library.path=D:\opencv310\opencv\build\java -Didea.launcher.port=7536 "-Didea.launcher.bin.path=D:\progs\IntelliJ IDEA 14.1.4\bin" -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\zipfs.jar;C:\Users\mrk\IdeaProjects\TestOpencvError\out\production\TestOpencvError;D:\opencv310\opencv\build\java\opencv-310.jar;D:\progs\IntelliJ IDEA 14.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.company.Main
Entering Main
Creating Mat
Finished successfully
Process finished with exit code 0
But when I compile the source and try to launch .class from console
java -Djava.library.path=D:\ com.company.Main
(I have copied opencv310.dll to root of my D drive and jar file to java/lib/ext to be sure it is found)
I get the following output:
Entering Main
Creating Mat
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n
_Mat()J
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.(Mat.java:24)
at com.company.Main.main(Main.java:13)
Which means that DLL is loaded but there is no method n_Mat found. As a proof, when launched without the -Djava.library.path flag the output changes to the following
Entering Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 in
java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.company.Main.main(Main.java:11)
I have tried to launch the app with IDEA's parameters, that is
java -Dvisualvm.id=11658625891829 -Djava.library.path=D:\opencv310\opencv\build\java -Didea.launcher.port=7536 "-Didea.launcher.bin.path=D:\progs\IntelliJ IDEA 14.1.4\bin" -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\zipfs.jar;C:\Users\mrk\IdeaProjects\TestOpencvError\out\production\TestOpencvError;D:\opencv310\opencv\build\java\opencv-310.jar;D:\progs\IntelliJ IDEA 14.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.company.Main
but still got the same error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n
_Mat()J
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.(Mat.java:24)
at com.company.Main.main(Main.java:13)
I want to stress once again: code works fine when is being run from within the IDE. The error only shows in console.
There are several similar topics on the net but generally it is the missed -D*library flag issue. I have shown that it is not the case for me
OpenCV + Java = UnsatisfiedLinkError
Javacv UnsatisfiedLinkError in windows 7
This topic has a link to probably solve the issue using javah tool but I don't find it appropriate for my case since launching from IDE works without correcting headers.
UnsatisfiedLInkError Eclipse JNI (works from command line but not in Eclipse) package names
I have tried building jar in IDEA too but it resulted in the same error
What steps could I try to get the code running from the console?
What is that extra-something that is being done by IDE that is hidden from the user which makes this big difference?

java.lang.UnsatisfiedLinkError: no so in java.library.path

When i'm trying to load the .so file from the Java, i'm getting error like this.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no yeslib.so 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.rct.micros.util.GetCustClass.getScratchCode(GetCustClass.java:76)
at com.rct.micros.util.GetCustClass.main(GetCustClass.java:39)
I have tried System.load(absoulte path) and System.loadLibrary(sofilename). Both are giving the same error. When i copy this so file into usr/lib/jvm package, it is working..
can anyone help how to get this solved using Java. i'm running on linux box.
It's possible that the library is on your path, but it can't be loaded for some other reason.
A trick I've used to debug problems like this is to run java -Xrunsofilename
-Xrun is the JVM option to load JVMPI libraries (the old profiling interface). If it succeeds, it will load the library and complain that it's not an agent library. But if it fails (hopefully!) it will print an error message. This is usually a more descriptive error message than what you get from the UnsatisfiedLinkError.

ZMQ - libzmq.so.3: cannot open shared object file: No such file or directory

I'm trying to embed zeroMQ in my app, I followed this guideline to install ZMQ, so till here everything works fine.
I have this line of code in my app:
ZMQ.Context m_context = ZMQ.context(1);
but above line of code raise below exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/libjzmq-812339378390536247.lib: libzmq.so.3: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
at java.lang.Runtime.load0(Runtime.java:792)
at java.lang.System.load(System.java:1059)
at org.zeromq.EmbeddedLibraryTools.loadEmbeddedLibrary(EmbeddedLibraryTools.java:136)
at org.zeromq.EmbeddedLibraryTools.<clinit>(EmbeddedLibraryTools.java:22)
at org.zeromq.ZMQ.<clinit>(ZMQ.java:38)
at com.castaclip.verticals.Messenger.<init>(Messenger.java:125)
at com.castaclip.verticals.PushMessenger.<init>(PushMessenger.java:30)
at com.castaclip.verticals.pushserver.App.setup(App.java:60)
at com.castaclip.verticals.pushserver.App.main(App.java:41)
The error is exactly pointing to this line.
P.S: its a little bit difficult to fully explain this question.. if you have any question plz let me know. thanks.
If you've successfully built libzmq and jzmq in that order, I would run:
$ sudo ldconfig
to update the system library cache. Then I would check to see if LD_LIBRARY_PATH is defined like Raffian mentioned, or set your library path explicitly to something like:
$ java -Djava.library.path=/usr/lib:/usr/local/lib
Finally I tried to figure out the problem.
I was using zeromq-2.1.10 and this was part of the problem.
So I installed zeromq-3.2.3 from the source and problem resolved.
I encountered a mystifying instance of this message when I:
# java -Djava.library.path=/usr/hf/zmq/lib/ -cp '/usr/hf/lib/*:.' com.zmqtest.MA
Exception in thread "main"
java.lang.UnsatisfiedLinkError: /usr/hf/zmq/lib/libjzmq.so:
libzmq.so.3: cannot open shared object file: No such file or directory
which was fixed with a solution that makes no sense at all to me:
# LD_LIBRARY_PATH=/usr/hf/zmq/lib/ java -Djava.library.path=/usr/hf/zmq/lib/ -cp '/usr/hf/lib/*:.' com.zmqtest.MA
wierd.

no usbJava in java.library.path

I got a .jar file from a code that works on Windows, and I'm trying to run it on Linux, but I keep getting this message, and don't know what to do.
Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: no usbJava in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at ch.ntb.usb.LibusbJava.<clinit>(LibusbJava.java:366)
at ch.ntb.usb.USB.init(USB.java:315)
at ch.ntb.usb.USB.getBus(USB.java:296)
at ch.ntb.usb.Device.initDevice(Device.java:102)
at ch.ntb.usb.Device.open(Device.java:222)
at TransmitterModuleHIDInterface.run(TransmitterModuleHIDInterface.java:28)
at java.lang.Thread.run(Thread.java:722)
I'm using the Java wrapper for the libusb-0.1 (I followed the installation instructions here).
Any help would be really appreciated!
You need to create a link to the shared library, as per the Linux installation instructions:
http://libusbjava.sourceforge.net/wp/?page_id=8
If you're having trouble building the shared library this might be of some help:
http://me.opengroove.org/2010/01/libusbjavaso.html
The sources for the library itself is under /libusbjava/trunk/LibusbJava/ in the SVN source tree.

Can't find/load swt-gtk

I'm trying to run an internal web browser using JWebBrowser. When I run the application in Netbeans environment it works perfectly. However, when I build the project and run the jar file I'm getting the following error:
NativeSwing[1]: Exception in thread "main" java.lang.UnsatisfiedLinkError: Could
not load SWT library. Reasons:
NativeSwing[1]: no swt-gtk-3721 in java.library.path
NativeSwing[1]: no swt-gtk in java.library.path
NativeSwing[1]: Can't load library: C:\Users\CCS.swt\lib\win32\amd64\swt-gtk-3721.dll
NativeSwing[1]: Can't load library: C:\Users\CCS.swt\lib\win32\amd64\swt-gtk.dll
I'm including the following libraries to the project:
DJNativeSwing.jar
DJNativeSwing-SWT.jar
DJNativeSwing-SWTAPI.jar
DJNativeSwing-SWTCore.jar
MozillaInterfaces-1.8.1.3.jar
swt.jar (version 3.7M5 for 64 bits.)
jna_WindowUtils.jar
jna-3.2.4.jar
and they're referenced by Manifest.MF by this way
Class-Path: lib/DJNativeSwing-SWT.jar lib/DJNativeSwing-SWTAPI.jar lib
/DJNativeSwing-SWTCore.jar lib/MozillaInterfaces-1.8.1.3.jar lib/DJNa
tiveSwing.jar lib/swt.jar lib/jna-3.2.4.jar lib/jna_WindowUtils.jar
What am I doing wrong?
Thank you.
You need to specify the java.library.path in the java command and aim it at the path to your .dll files. For example,
java -Djava.library.path=lib -cp ...
Ok, I found the solution. The problem was about the dll generation. I was using 3.7m5 version, I downloaded a previous version (3.7) and the application ran properly.
Thank you for your help.
Regards.

Categories