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?
Related
I can see that this question has been asked before, but I have not found previous answers useful - specifically my issue is following Princeton University's 'Algorithms' course on Coursera here and using their algs4.jar file to access ostensibly necessary utilities. I have never used Java before but this seemed like such a good course, I'm trying to muddle through rather than switching to a 'worse' course in a language I know. I have also found a thread specifically on this issue here and a Reddit question here, which were equally as useless as the other questions which had this problem, but not with the Princeton's algs4.jar file.
This is my code, I haven't bothered to finish it but it should run. Before anybody asks, I've commented out everything except the first if (StdIn.isEmpty()) check and it still gives me all the same compiler/interpreter errors, so this is nothing to do with it being half-finished - StdIn.isEmpty() and StdIn.readString() are supposed to be provided by algs4.jar:
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;
import edu.princeton.cs.algs4.StdRandom;
class RandomWord
{
public static void main(String[] args)
{
if (StdIn.isEmpty())
{
System.out.println("Nothing to read.");
return;
}
String curr_selected_word;
double curr_probability = 0.0;
int i = 0;
while (!StdIn.isEmpty())
{
String current_string = StdIn.readString();
System.out.println("> " + current_string);
}
}
}
Following the advice of previous threads, I compile like this:
javac -cp "./algs4.jar" RandomWord.java
Which works fine. Running java RandomWord, I get this large messy error:
Exception in thread "main" java.lang.NoClassDefFoundError: edu/princeton/cs/algs4/StdIn
at RandomWord.main(RandomWord.java:13)
Caused by: java.lang.ClassNotFoundException: edu.princeton.cs.algs4.StdIn
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
The accepted answer on the other question was to reference the .jar file explicitly, like this:
java -cp "C:\Coursera\Algorithms\Part 1\Java Solutions\HelloWorld;C:\Coursera\Algorithms\Part 1\Java Solutions\algs4.jar" RandomWord
Which gives me the exact same error. There is also a comment on the Reddit thread that uses the -classpath instead of -cp flag, which at least gives a different but stranger error:
>java -classpath ./algs4.jar RandomWord
Error: Could not find or load main class RandomWord
Caused by: java.lang.ClassNotFoundException: RandomWord
Putting quotes around the .jar filepath, or providing the absolute filepath, all produce the same error.
I Googled this and predictably it is caused by not having a main entry-point, but... see code above?
Lastly, the installer for the Coursera course apparently installs some Bash commands (see here) called javac-algs4 and java-algs4 which is supposed to sort out all this classpath nonsense for me. So I crack open Bash, and:
>javac-algs4 RandomWord.java
'javac-algs4' is not recognized as an internal or external command,
operable program or batch file.
I have restarted since running the installer. I would add these to my PATH manually, but I don't even know where they are; the C:\Program Files\LIFT-CS folder that their installer installs into only contains a pissing uninstaller. So I'm absolutely losing my rag and at my wits' end after spending over 7 hours just trying to start this course, not even getting stuck on the problems or the content. When will content creators learn we don't want your in-house IDE with no dark mode and libraries that do nothing but rename every function to camel-case?
Anyway, if anyone has encountered this or knows what I could do to fix it, help would be appreciated.
You can try this -
javac -cp .;<insert class path> RandomWord
I was facing the exact same issue, I ran javac -cp .;.lift/algs4.jar RandomWord and it works. (My compiled class was in the same directory as .lift)
This worked for me on a Mac. Copy algs4.jar to the root of your project, then:
javac -cp ".:./algs4.jar" RandomWord.java
java -cp ".:./algs4.jar" RandomWord
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.
I am using Netbeans to create a java application. The program works fine when I hit run in Netbeans. The problem is when I build the app and run it from the dist folder it throws the UnsatisfiedLinkError. I know this is caused by the libraries.
The error message is:
"Exception in thread "main" java.lang.UnsatisfiedLinkError:
jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J"
Thank you for your help.
When I try to do a simple "Hello World" java application I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: /path/to/mainarg*
Caused by: java.lang.ClassNotFoundException: first.Skeleton
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I am running on Mac OS 10.8.1 and am running Java 1.6. I have checked my run configurations to make sure the main argument can be found. For the sake of simplicity I have also tried to use the default JRE of java 1.6 that is included with mac. The build configuration I have used is also correct and pointed to the right place.
When I followed this tutorial online, and executed the commands over the terminal I get the same error. What am I missing? I don't think it is an Eclipse problem anymore, but something bigger. Any advice would be greatly appreciated.
Here is the code I tried to run:
public class Test{
/* This is my first java program.
* This will print 'Hello World' as the output
*/
public static void main(String[]args){
System.out.println("Hello World");// prints Hello World
}
}
I put the code on my Desktop for simplicity. I went to /usr/tyler/desktop then made the script an executable with "javac Test.java", and when I tried to run it with "java Test.java" I then got the error.
Here are the other tutorials I have followed:
-Java Compilation error on Mac
-HelloWorld with Eclipse on Mac
-Along with many others from SO and elsewhere
EDIT:
Thank you for the help. The terminal issue has been resolved. However, if anyone has any advice on what could be going wrong with Eclipse, that would be appreciated.
You need to run ...
"java Test"
You cannot execute the java code, you need to execute the compiled class file. The java executable will look for a .class file with the name Test.
execute or run
java Test
instead of
java Test.java
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.