Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NO opencv_java300 in java.library.path [duplicate]

Tags:

java

opencv

jar

Thanks in advance..

I have a project that uses opencv-300.jar as external library. I have tried this in eclipse and in natBeans. In both it is working successfully when I am running my project from IDE itself. I want my project to export it as a runnable (or executable) jar. I placed my opencv_java300.dll file in source folder with main java file and given its name in

 System.loadLibrary("opencv_java300");

I placed opencv-300.jar in external jar libraries and all other files which are needed in Main program. it is working successfully when running from IDE but when I am creating executable jar, it shows an error

   Exception in thread "main" java.lang.UnsatisfiedLinkError: no     
   opencv_java300 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 CropFaceImage.main(CropFaceImage.java:27)

Please tell me Is there any way to give java.library.path in program itself. My project is working sucsessfully even when I have removed path for opencv_java300.dll file in external library.

like image 587
Anuj Avatar asked Jul 08 '15 07:07

Anuj


2 Answers

You can use a command line argument as below and call your class which has the main

java -Djava.library.path="Folder which contains your dll" ....
like image 122
Kalyan Chavali Avatar answered Nov 10 '22 23:11

Kalyan Chavali


I tried to pass the command which contains path for opencv but I found no other way. Somehow i tried something which created my jar and it is properly running. I copied the opencv_java300.dll file and put it in the directory which is next to the my jar file and did same for all supporting files. I used following code to do so.

String opencvpath = System.getProperty("user.dir") + "\\files\\";
String libPath = System.getProperty("java.library.path");
System.load(opencvpath + Core.NATIVE_LIBRARY_NAME + ".dll");
like image 12
Anuj Avatar answered Nov 10 '22 23:11

Anuj