Issue
I have an issue with specifying the path to the x64 OpenCV DLL.
I was using
static{
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
to load the OpenCV x64 DLL and it worked fine in NetBeans (using -Djava.library.path=".\opencv\x64"
but not with a .jar outside of the IDE.
Running the built .jar (with or without -Djava.library.path=".\opencv\x64"
) throws:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no
opencv_java330 in java.library.path
There are countless questions and solutions regarding this issue here.
But, they all require a relative path to the folder containing the DLL -- I cannot specify either an absolute or a relative path to the folder where the x64 OpenCV DLL is located.
System.loadLibrary("%UserProfile%/Documents/NetBeansProjects/ProjectName/opencv/x64/");
throws an
java.lang.UnsatisfiedLinkError: no %UserProfile%/Documents/NetBeansProjects/ProjectName/opencv/x64/ in java.library.path
error.
Direct path to the folder throws the same error.
Just System.loadLibrary("/opencv/x64/");
(with or without the leading dot) also throws the same error.
Any help with this issue would be greatly appreciated.
Solution
Probably you have a wrong order of the parameters. Find below a working example.
Assuming the following structure.
bin\
dist\
opencv\x64\opencv_java320.dll
src\foo\Test.java
Test.java
package foo;
class Test {
public static void main(String[] args) {
// note: the parameter is the library name, no extension, no path
System.loadLibrary("opencv_java320");
System.out.println("library loaded");
}
}
class path on file system
compile
javac -d bin/ src/foo/Test.java
run
java -cp bin -Djava.library.path=opencv/x64 foo.Test
output
library loaded
class inside a JAR file
create executeable JAR file
echo Main-Class: foo.Test > manifest.mf jar cfm dist/application.jar manifest.mf -C bin/ .
execute the JAR file with relative path
java -Djava.library.path=opencv/x64 -jar dist/application.jar
execute the JAR file in the current directory
cd dist java -Djava.library.path=../opencv/x64 -jar application.jar
output for both JAR executions
library loaded
Answered By - SubOptimal