RaiMan / SikuliX1

SikuliX version 2.0.0+ (2019+)
https://sikulix.github.io
MIT License
2.77k stars 355 forks source link

ExceptionInInitializerError in Pattern.<init> #306

Closed gfiedler closed 4 years ago

gfiedler commented 4 years ago

I created the jython script

#!/bin/sh
exec java -jar jython-standalone-2.7.1.jar -Dpython.path=sikulixapi-2.0.1.jar "$@"

When I execute pattern.py

from org.sikuli.script import Pattern
Pattern('image/OK.png')

with

jython pattern.py

then I got the following error

Traceback (most recent call last):
  File "pattern.py", line 2, in <module>
    Pattern('image/OK.png')
        at org.sikuli.script.Pattern.<init>(Pattern.java:123)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:211)
java.lang.ExceptionInInitializerError: java.lang.ExceptionInInitializerError

In the Wiki I found the hint

Make sure a link to the libopencv_java.so is available in your loader path at runtime.

So I have installed

sudo apt install libopencv3.2-jni

which created a file /usr/lib/jni/libopencv_java320.so (Ubuntu 18.04).

I've tried several things like ldconfig, LD_LIBRARY_PATH, -Djava.library.path= with no success.

I would appreciate it very much if you would help me how to make the link in the runtime loader path.

RaiMan commented 4 years ago

use ln -s /usr/lib/jni/libopencv_java320.so /usr/lib/libopencv_java.so

gfiedler commented 4 years ago
# cd /usr/lib
# ln -s /usr/lib/jni/libopencv_java320.so libopencv_java.so
# ldconfig
# ls -l libopencv_java*
lrwxrwxrwx 1 root root 17 Feb 10 10:43 libopencv_java320.so -> libopencv_java.so
lrwxrwxrwx 1 root root 33 Feb 10 10:43 libopencv_java.so -> /usr/lib/jni/libopencv_java320.so
# ldconfig -p | grep libopencv
        libopencv_xphoto.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_xphoto.so.3.2
        libopencv_xobjdetect.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_xobjdetect.so.3.2
        libopencv_ximgproc.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_ximgproc.so.3.2
        libopencv_viz.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_viz.so.3.2
        libopencv_videostab.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_videostab.so.3.2
        libopencv_videoio.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_videoio.so.3.2
        libopencv_video.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_video.so.3.2
        libopencv_text.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_text.so.3.2
        libopencv_surface_matching.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_surface_matching.so.3.2
        libopencv_superres.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_superres.so.3.2
        libopencv_structured_light.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_structured_light.so.3.2
        libopencv_stitching.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_stitching.so.3.2
        libopencv_stereo.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_stereo.so.3.2
        libopencv_shape.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_shape.so.3.2
        libopencv_saliency.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_saliency.so.3.2
        libopencv_rgbd.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_rgbd.so.3.2
        libopencv_reg.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_reg.so.3.2
        libopencv_plot.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_plot.so.3.2
        libopencv_photo.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_photo.so.3.2
        libopencv_phase_unwrapping.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_phase_unwrapping.so.3.2
        libopencv_optflow.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_optflow.so.3.2
        libopencv_objdetect.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so.3.2
        libopencv_ml.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_ml.so.3.2
        libopencv_line_descriptor.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_line_descriptor.so.3.2
        libopencv_java320.so (libc6,x86-64) => /usr/lib/libopencv_java320.so
        libopencv_imgproc.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2
        libopencv_imgcodecs.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2
        libopencv_highgui.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.3.2
        libopencv_hdf.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_hdf.so.3.2
        libopencv_fuzzy.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_fuzzy.so.3.2
        libopencv_freetype.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_freetype.so.3.2
        libopencv_flann.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_flann.so.3.2
        libopencv_features2d.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_features2d.so.3.2
        libopencv_face.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_face.so.3.2
        libopencv_dpm.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_dpm.so.3.2
        libopencv_datasets.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_datasets.so.3.2
        libopencv_core.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2
        libopencv_ccalib.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_ccalib.so.3.2
        libopencv_calib3d.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.2
        libopencv_bioinspired.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_bioinspired.so.3.2
        libopencv_bgsegm.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_bgsegm.so.3.2
        libopencv_aruco.so.3.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libopencv_aruco.so.3.2

The issue still exists.

Java versions:

RaiMan commented 4 years ago
# ls -l libopencv_java*
lrwxrwxrwx 1 root root 17 Feb 10 10:43 libopencv_java320.so -> libopencv_java.so
lrwxrwxrwx 1 root root 33 Feb 10 10:43 libopencv_java.so -> /usr/lib/jni/libopencv_java320.so

... this looks odd: like some roundabout

gfiedler commented 4 years ago

This is a listing of /usr/lib. The first symlink is created by ldconfig.

RaiMan commented 4 years ago

In my test setup the opencv libs are in /usr/local/lib (installed with linuxbrew) The libopencv_javaxxx.so is in /usr/local/share/java/opencv4/ (manually built)

I run java -jar sikulixapi.jar -v -r test.js (a simple print("hello")

Without any symlink opencv_java.so I get:

[1770 debug] RunTime:loadlib: trying opencv_java411
[error] RunTime:loadLib: opencv_java (failed) probably dependent libs missing:
no opencv_java in java.library.path: [/usr/java/packages/lib, /usr/lib/x86_64-linux-gnu/jni, /lib/x86_64-linux-gnu, /usr/lib/x86_64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
[error] Save your work, correct the problem and restart the IDE!

With a symlink in any of the above listed folders it works as it should.

So I gues you have to sort out your locations and symlinks.

gfiedler commented 4 years ago

Your test setup succeeds with my environment.

No ExceptionInInitializerError anymore after changing my jython script to

#!/bin/sh
exec java -cp jython-standalone-2.7.1.jar:sikulixapi-2.0.1.jar -Dpython.path=sikulixapi-2.0.1.jar org.python.util.jython "$@"

Thank you anyway!