I have almost the same situation as in this question: Trying to make java application (Executable Jar) that uses OpenCV portable. Getting unsatisfied link error. And this question and questions linked and related to this one helps me to understand more. But I still need help with my problem. My question actually splits onto two interrelated questions:
How to determine files of opencv library actually needed for my application (just to grab video)
On my development computer there is a number of directories with obviously the same collection of dll files of opencv2.4.2 (as i understand only dll files needed):
I understand division onto x86 and x64, but what about mingw/vc9/vc10?
How to organize them to my portable build?
When i'm creating runnable jar from my project, i have nice option "Copy required libraries into sub-folder next to the generated JAR". The folder usually has name of form "_myApp__lib". Suppose I placed required dll files to that sub-folder as well. How to make my runnable jar see them? And can i do this without -Djava.library.path? And is it possible to place dll files to separate jar?
Related to part 1 of the question:
As i found out, mingw, vc9 and vc10 are different c++ compilers used to create corresponding builds, but i still doesn't know what will be changed if i would use mingw or vc9. I just chose vc10 as more familiar and fresh. Any explanations here will be appreciated.
But these files is not all files needed! There is opencv/build/common/tbb folder where you will find ia32 (x86 version, as i understand) and intel64 (x64 version as well) folders which in turn divided by compiler subfolders. So i chose vc10 again.
Some of dll files, for example for object detection, obviously does not required in my project, but i decided to leave them all. After all they take only 42Mb insteed of about 2,5Gb of whole unpacked openvc library.
Now about part 2 of the question
As suggested in many question answers (see Trying to make java application (Executable Jar) that uses OpenCV portable. Getting unsatisfied link error and adding openCV to java buildpath in eclipse and linked questions), you may setup path windows environment variable or use java comand line -Djava.library.path switch to help your application find those dll files or place them to one of the folders in path windows environment variable. You even can place whole library to the root of the C: drive.
But there is better decision! You can change Java System property java.library.path at any moment while your application running using this trick:
public static void setLibPath(String path){
System.setProperty( "java.library.path", path );
Field fieldSysPath;
try {
fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
An idea was taken from this page and you may find similar trick here.
With this code snippet you may place all dlls to the your_opencv_subfolder subfolder of your app's runnable jar folder and then do something like
setLibPath(System.getProperty("user.dir")+"\\your_opencv_subfolder")
before any use of opencv library.