[2.0.4] SikuliX API: Error with runnable fat jar --- opencv dll not available at runtime

Asked by Ralph

Hi all,

When I export as a fat jar and run on another Win10 PC with Java installed I get the following error when I use screen.exist, hover, click etc

java.lang.UnsatisfiedLinkError: 'long org.opencv.core.Mat.n_Mat()'

Pom is below. Just wondering if you have seen this before or have any suggestions? Note I'm running 2.0.4 because 2.0.5 has an issue locating images embedded in the jar

Thanks in advance

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">



              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">


Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :

ok, I will check/test and make you a suggestion for a workaround asap.

Revision history for this message
RaiMan (raimund-hocke) said :

put the following at the top of your main class:

static { new Finder(new Screen().capture(0, 0, 1, 1)); }

Looks a bit odd, but it takes care, that the <appdata>\Sikulix folder is created and the OpenCV DLL is exported and loaded, before any SikuliX features are touched.

Revision history for this message
Ralph (rnimbin) said :

Hi, thanks heaps but still get a similar error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'long org.opencv.core.Mat.n_Mat()'
        at org.opencv.core.Mat.n_Mat(Native Method)
        at org.opencv.core.Mat.<init>(Mat.java:30)
        at org.sikuli.script.Finder$FindInput2.<init>(Finder.java:1167)
        at org.sikuli.script.Finder$FindInput2.<init>(Finder.java:1161)
        at org.sikuli.script.Finder.<init>(Finder.java:34)
        at utils.MainClass.<clinit>(MainClass.java:25)

The PC I am running on is Win10 and has Java DevKit 17.0.2 installed. The Java environment variables are set and I have copied opencv_java342.dll to various system folders in the path to see if that helps.

The jar runs standalone without error on the IDE PC which has the same OS and same version/configuration of Java. The only solutions installed from the eclipse marketplace are Maven (Eclipse m2e) and TestNG.

I have tried creating the fat jar with maven-assembly-plugin and maven-shade-plugin and get the same error

The following folders exist under <appdata>\roaming\sikulix
SikulixLibs (contains opencv_java342.dll)

Revision history for this message
Ralph (rnimbin) said (last edit ):

[update] I replaced "static { new Finder(new Screen().capture(0, 0, 1, 1)); }" with System.loadLibrary(Core.NATIVE_LIBRARY_NAME) and copied opencv_java342.dll to <java>\bin and the error is gone now. Application now works on the non-IDE PC :)

Revision history for this message
RaiMan (raimund-hocke) said :

That is really odd.

... and I do not understand it :-(

I cannot reproduce it here, because I only have my one dev-Win11 available, where everything works fine, including the case with the fat jar from command line.

I do not have any Java specific environment variables set - running java is done with a command-file, that executes the exe from Java's .../bin folder.

This is the equivalent in SikuliX to your solution (copy to Java/bin and System.loadLibrary()):

the add-on is the export of the libs folder to <appdata>.
And the difference is that I use System.load(<absolute-path-to-opencv-dll-in-appdata>).
For some reason this silently does not make the dll available.

For now, I cannot do anything else, but will add an early test in 2.0.6, wether the System.load() was successful and the dll is available for opencv.java.

One more thing:
It would be helpful for me to get the source of your failing main class.
If that is ok for you, then send it per mail: sikulix---at---outlook---dot---com.
If not, no problem.

Thanks for your time anyways.

Can you help with this problem?

Provide an answer of your own, or ask Ralph for more information if necessary.

To post a message you must log in.