3

I have made JavaFX Project with using Opencv 3.1 Java library in it.

The thing is that my project runs completely perfect from the IDE but when I try to run the .jar file from the dist folder it throws the unsatisfied link error.

I searched about this problem already and found many answers but none solved mine.I think may be those solutions are for older versions.

My Main Method is as follows :-

 public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        launch(args);
    } 

I have also set the library path correctly :

enter image description here

and also have the .dll file in the specified location

enter image description here

The App runs completely as expected if I run from IDE !

PS: I also tried to put the project in Eclipse and try creating jar but same thing happens, it runs in IDE but not when I run the jar

Error details :

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: 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.Rein.rteapp.MainApp.main(MainApp.java:129)
JoshDM
  • 4,939
  • 7
  • 43
  • 72
Vishal Nair
  • 2,141
  • 3
  • 26
  • 39
  • I have this question also. Did you ever figure this out? – mccoyLBI Apr 11 '17 at 17:11
  • @mccoyLBI Yes .Thanks for asking or I was thinking only I had this problem because the solution is pretty intuitive. :) Now I know may be there are few out there like us so I just posted it as answer ! – Vishal Nair Apr 20 '17 at 15:28
  • I just figured this out 5 minutes ago and it was exactly what you said! If only I checked SO earlier... – mccoyLBI Apr 20 '17 at 16:03

1 Answers1

3

I found the solution.

I solved it by using relative paths wherever I needed to reference some external resources.So Anywhere you use System.getProperty("user.dir") it refers your app root folder.

Eg:- if you have referenced something like :-

String path =  System.getProperty("user.dir") + "\\MyResourceFolder";

Then you will have to copy 'MyResourceFolder' into the folder where jar is created(next to the jar file).

The solution runs in IDE because we have copied the resource folders into our Project root folder but when we create the jar file those resource file don't get copied to the jar's folder so we have to manually copy all those resource folders and its content next to where the Jar file was created for maintaining relative paths when we run the jar.

Vishal Nair
  • 2,141
  • 3
  • 26
  • 39
  • *Anywhere you use System.getProperty("user.dir") it refers your app root folder*. That is simply *wrong* I'm afraid. It refers to the [current directory](https://technojeeves.com/index.php/aliasjava1/91-find-the-current-directory-in-java) (where your app has been run from) which could be entirely different – g00se Jun 26 '23 at 23:40