Opencv Java exception - java
I'm using Windows 7 and getting this exception when trying to run a Java project that uses opencv libraries:
Exception in thread "main"
java.lang.UnsatisfiedLinkError: no opencv_java 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 org.opencv.highgui.Highgui.<clinit>(Highgui.java:416)
at teste.main(teste.java:21)
What did I do wrong? Is some import missing?
I want to create a simple Java project in Eclipse (not Android), that uses openCV.
So I've extracted javacv from OpenCV-2.4.2.exe file to C:\
Then executed "cmake -G "MinGW Makefiles" -DBUILD_opencv_java=ON
C:\opencv" command and after that, "mingw32-make". Everything was
build without errors or warnings
After I've added opencv dll's to my Environment Variables
This exception is raised because the system is trying to find native libraries that OpenCV needs for this specific platform, and does not find them.
Exception in thread "main"
java.lang.UnsatisfiedLinkError: no opencv_java in java.
To solve this error:
If you are using opencv version < opencv 2.4.6 then the answer given by #user3033420 is the solution.
If you are using version >= opencv 2.4.6, then the jar has a constant variable in Core class named NATIVE_LIBRARY_NAME that you give to the loadLibrary() function in FaceDetector class to include features of opencv in your project, you probably already have this:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Using the above named constant, there is no need to remember name of strang dll files.
Add the opencv 2.4.9.jar to the build path from project preferences as:
Window -> Preferences -> Java Build Path –> Add Library -> User Libraries ->
User Library -> & click New
You will see a dialog as below. Add opencv-2.4.9 as Library Name & click Ok.
Then Add External Jar & locate your opencv jar & click ok. Then expand opencv-2.4.9.jar & click on Native Library Location (None) as shown below :
Necessary step: enter the location of the folder containing native library used by "opencv-2.4.9" & then click OK as shown below :
So now the jar now has all the native libraries it needs to do the work. Rebuild the java program and everything should compile and run as designed.
If you get this error:
Exception in thread "main"
java.lang.UnsatisfiedLinkError: no opencv_java in java.library.path
It probably means you are shooting from the hip, programming by brownian motion, trying to get openCV to work. Like trying to figure out how an airplane works in flight by pressing all the buttons furiously. You're going to have a bad time.
What the error means:
Eclipse is telling you that the jar file can't find libraries it needs to do its job. So naturally it's not going to work until you make them available. You've got to find a tutorial on "how to build openCV from source" on your particular platform: (windows, mac, linux, etc), (32bit, 64bit, etc).
Basically, you glossed over the 'Native library location' settings, or didn't set them correctly, and so the jar can't find its support libraries written in C.
How do fix it, thousand foot view:
Download the source code for openCV for your operating system.
Follow the directions to build openCV from source.
Copy the jar into a lib directory in your Java project.
Configure the jar to look for its native libraries by setting the "native library location" to the build/lib directory under the path where you built openCV from source.
Clean build the java project, and the UnsatisfiedLinkError should go away.
This blog talks about the steps above in step-by-step detail: https://udallascs.wordpress.com/2014/03/30/adding-opencv-and-configuring-to-work-with-eclipse-and-java/
Why can't this just be a simple jar?
Because most of openCV is written in the C programming language. And the jar file you are using is just a window into that C world. So it's a rube Goldberg machine. You'll see these sorts of things all over the place in the real work world, so pay attention, you are getting an education here.
Trying to load the library by doing this:
System.loadLibrary("opencv_java244")
Or by doing this:
System.loadLibrary("opencv_java244")
Didn't work - still got the same error.
Finally what worked was providing the full path to the dylib file and using:
System.load(new File("/usr/local/Cellar/opencv/2.4.10.1/share/OpenCV/java/libopencv_java2410.dylib").getAbsolutePath());'
I'm using HomeBrew but however you installed it just find the file and uddate the path.
I find solution. Actual dll is located at openCV\opencv\build\java\x64\ folder. In my case its name is opencv_java247.dll , So i have changed java code line
System.loadLibrary("opencv_java244")
to
System.loadLibrary("opencv_java247")
I also set native library location as E:/Sagar_tools/tools/openCV/opencv/build/java/x64 (full path to dll) in build path.
The function loadlibrary tries to find the name of the the DLL in your PATH variable -- check the DLL name. You can also try System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
In that case, you should give the path for jvm to where the opencv dll file is intalled as : -Djava.library.path="C:\opencv\build\java\x64"
and add the code as :
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
As, i try this in my netbeans ide and my problem is solved.
Related
No dll file in OpenCV 4.0.0
I have been trying to use OpenCV with Java without success. I am currently running Linux. I downloaded the OpenCV library from Github, but when I try to run any program, it gives me an error on the line: System.load(Core.NATIVE_LIBRARY_NAME); The error is "Exception in thread "main" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: opencv_java400" I have been told I need to provide a path to a .dll file; however, the current version of OpenCV appears not to contain any .dll files. Any suggestions would be appreciated, thank you.
The message of the Exception is everything you need. You are supposed to provide an absolute path to the file. Normally you would put the native libraries as resource in your java package (*.jar). Before loading you must extract the file to a temporary directory of the executing system and then invoke the System.load(..). As already mentioned a dll typically names a dynamic runtime library on windows os.
Referenced Library in Java Project only finds native dll when I specify where they are in IDE
I have a library in eclipse that uses native libraries (two dll). The dlls are in the same folder as the jar. When I run the application there is an error: java.lang.UnsatisfiedLinkError: no xx in java.library.path When I link the library by double click on native library location, then running it works. However, I don't want to have to do this, I want it to work with out having to configure it via the IDE. I want the library to be plug and play. Q1: Where is the convetional location to put .dll referenced by a .jar library. Q2: How can I make sure when someone references my library in eclipse it works without further IDE configuration?
Error explains it clearly that your native libraries are not in the default location of java.library.path You just have to set property java.library.path to the folder where all native libraries are stored. You can do this by giving argument in the command line -Djava.library.path=C:/nativeLibs/ OR Copy your libraries to default location of java.library.path Refer Default Java library path? for default location of java.library.path
Matlab JavaBuilder jar in Eclipse- missing mkl.dll?
I've been given some jars generated by the Matlab JavaBuilder by some colleagues. Some work fine when I use them in my Eclipse project, but a new one fails with this error: libmwblas: load error: mkl.dll And a message about the dll not being found. When I look in the Matlab Compiler Runtime bin folder there is a mkl.dll in there. Any suggestions as to why Matlab can't or won't see the dll?
Your JARs are using JNI and trying to resolve the required DLL. Option one is to resolve this is by adding /bin folder you mentioned to your Windows PATH so that Java is able to resolve this (and probably some other) DLLs. Another (cleaner for development purposes) option is to configure Eclipse by specifying Native library location for the JAR which attempts to load DLLs. Go to Java Build Path of your project, then find the appropriate JAR in Libraries tab, then expand it and set Native library location.
Unsatisfied Link Error Help Java JNI Eclipse
Hi I am trying to run a project in eclipse and am getting the runtime error: Exception in thread "main" java.lang.UnsatisfiedLinkError: mywrapperclass.nativemethod()V I only get the error code when I call a native method in the wrapper class from my main. I have looked around on many forums and blogs/websites and haven't been able to fix this. Debug and my browsing have me led me to thinking that the problem lies in the project not being able to find the native methods within the dll. I had a lot of trouble getting eclipse to find the .dll and eventually solved this by placing the dll in the system32 folder. Thanks in advance
Project > Properties > Java Build Path Click on the arrow of the JAR that needs the DLL library. Native library location You have to specify the location of the DLL library.
Easiest way to bundle the dlls with eclipse plugin is create a folder structure under the plugin like this "os/win32/x86" for x86 architecture and place your dlls there. and load the libraries like this in your plugin code System.loadLibrary("Dll name");
open .classpath in the project location Set the dll path as "value" for "CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" attribute
When I run the .jar, I get a "No lwjgl in java.library.path" error
I'm making a basic game in Java using the LWJGL Library via Netbeans. I've created a library with the lwjgl, lwjgl_util, and jinput .jar's, and I added -Djava.library.path=C:\LWJGL\native\windows to the "Run" category in the project's properties. When I run the file in Netbeans, it runs perfectly with no issue. But when I run the .jar via double-clicking the file, nothing pops up (not even the momentary cmd error window, as far as I can tell). And when I run the file via command line, I get: C:\Users\200160765>java -jar "C:\Users\200160765\Documents\NetBeansProjects\Game \dist\Game.jar" Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr ary.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at org.lwjgl.Sys$1.run(Sys.java:73) at java.security.AccessController.doPrivileged(Native Method) at org.lwjgl.Sys.doLoadLibrary(Sys.java:66) at org.lwjgl.Sys.loadLibrary(Sys.java:82) at org.lwjgl.Sys.<clinit>(Sys.java:99) at org.lwjgl.opengl.Display.<clinit>(Display.java:130) at game.Draw.createWindow(Draw.java:198) at game.Draw.init(Draw.java:214) at game.Draw.run(Draw.java:56) at game.Main.main(Main.java:9) I've tried moving the DLL's and .jar library files around to the 'lib' folder in the same directory as Game.jar, and moving them to the same directory as Game.jar, but I get the same error. Could someone help me as to why I can't seem to get this working outside of netbeans?
you have to point the jvm to where the native files are located using a command line parameter -Djava.library.path="path/to/natives". You could use a batch (.bat) file to specify this and start your application for you. Alternatively you can use a tool like JarSplice to create a single executable jar file from all your jars and at the same time include your native files inside it. It automates the tricky part of specifying the natives manually and provides a nicer end user experience. To use JarSplice just select your game.jar, lwjgl.jar, lwjgl_util.jar, and jinput.jar in the jars tab. Then all the *.dll, *.so, *.dylib and *.jnilib files in the natives tab. Add your main class on the class tab and create the single executable jar.
LWJGL needs the native components for your particular platform to be in java.library.path. These are in the subdirectory native in the LWJGL distribution and end in .so on Linux, OSX and Solaris and .dll for windows.
When I had this issue, it was because i accidentally put the argument to specify the location of the natives (-Djava.library.path=/native/) in the field called 'Arguments' under the run category of the options panel, instead of 'vm Options'. As seen here: http://s30.postimg.org/6f90akidt/Capture.png
And yet another way to do this is with Java Web Start (jnlp): http://lwjgl.org/forum/index.php?topic=3763.0 This makes sharing your project easier in some ways.
I had this problem and fixed it using jarSplice (http://ninjacave.com/jarsplice) make sure you delete all of the preplaced natives in your jar before you create the fat jar, otherwise it will create a duplicate error
I also got the same error and then realised that I named the file "my_lib.zip" instead of "my_lib.jar". Maybe it may help someone.
Another thing to check: If you are using a 32 bit JVM, you need 32 bit libraries. (Even on a 64 bit OS) If you are using a 64 bit JVM, you need 64 bit libraries.