[2.0.5] use images from a jar

Asked by Henri Gomez

There is often mentions of 2.0.6 but it was never released nor tagged in GitHub.
Did there is plan to release it ?

I tried to get working images from a jar in 2.0.5 but without success.
Images are stored in src/main/ressources/images in a Maven project and I've seen reports about problems and bug in 2.0.5, fixed in 2.0.6 (ie: https://bugs.launchpad.net/sikuli/+bug/1960350)

Thanks a lot

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Henri Gomez
Solved:
Last query:
Last reply:
Revision history for this message
Henri Gomez (henri-gomez) said :
#1

Alternativly, I would welcome code demonstrating how to get images from jar in 2.0.5 (latest version in Maven Central).
Thanks

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

--- 2.0.6
.. is still snapshot only (links on the GitHub readme page)

--- 2.0.5
... images from jar 2.0.5???
I do not understand what you want to do

Revision history for this message
Henri Gomez (henri-gomez) said :
#3

2.0.6

Snapshots are too risky and volatile, any ETA for release?

2.0.5

I would like to know if it's possible to get images bundled inside a jar in Sikuli 2.0.5 and if so, a sample code to do it.

Thanks

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

2.0.6 final: no idea - sorry

2.0.5: images from jar - ok, got it.
programming in Python or in Java?

Revision history for this message
Henri Gomez (henri-gomez) said :
#5

I would help to have more 2.0.x releases.
In well known state over the time.

For sample, in Java please 🙏

Revision history for this message
Henri Gomez (henri-gomez) said :
#6

I'm still battling from make images available from ressources dir.
Help would be very welcomed.

Project is using sikuli 2.0.5 (from Central), Java 17 and Maven 3.8.7
Images are stored in src/main/resources/images directory and bundled in jar

I tried with add(URL), it didn't works neither

    URL url = getClass().getClassLoader().getResource("images");
        logger.debug("URL is " + url);

        if (ImagePath.add(url)) {
            logger.info("Initialized images in jar support");
        } else {
            logger.error("Cannot initialize images in jar support");
        }

No error reported at that time but later on when calling new Pattern("xxx.png");

Thanks for your help

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

ok. understood.
I will set up a case and try to find a solution.
Hopefully within 2 days.

Revision history for this message
RaiMan (raimund-hocke) said (last edit ):
#8

Ok, this is a possible workaround in 2.0.5 in Java:

it is only the basic approach to get an image from a jar as a SikuliX useable object.

- make sure, that the jar containing the images has a class def and is on the classpath at runtime

    Class<?> aClass = Class.forName("<someClassDef>"); // locate the class ref
    URL url = aClass.getResource("<imageFolder/image.png>"); // locate the image as jar url
    Image image = Image.create(url); // create an Image object to use with the Region and Pattern classes
    Match match = new Screen().exists(image); // try to find the image on screen

- <someClassDef> a class in the images jar (in my case: com.sikulix.JarImages as main class)

- <imageFolder/image.png> an image in the jar (in my case: /jarimages/jarimg.png)

- my case: jar content:
/com/sikulix/JarImages.class
/jarimages/jarimages.py
/jarimages/jarimg.png
/META-INF/...

before packing the jar (with Maven in my case) you can build the image list in the SikuliX IDE using the jarimages as scriptfolder

Revision history for this message
Henri Gomez (henri-gomez) said :
#9

Perfect, it works as a charm.

Thanks a lot for the sample code