IntelliJ IDEA artifact.jar and ImagePath

Asked by Jaroslav Novotny on 2020-10-17

Hello, I am having trouble locating pattern images bundled inside .jar in IntelliJ IDEA IDE.

My project is setup like this:

And the code is:

for (ImagePath.PathEntry path : ImagePath.getPaths()) {
    print(String.format("ImagePath: %s", path) + "\n");

Which works nicely when I run the project. I get:


And everything works. But when I try to pack it inside .jar and I build an artifact and run it, I just get:


Weirdly the ImagePath.add("Main/patterns/") returns true. But finding patterns does not work.

This is the .jar structure when I unzip it:

Thanks for any help.

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

In the jar there is a folder "main" and your running class is named "Main".

This might lead to a confusion.

I made a new project just to investigate, got some new info. I was hoping it was conflict in the "main" name, but looks like something else.

This is the code:

import org.sikuli.script.*;
public class SikuliTest {
    public static void main(String[] args) {
        boolean path_add_success = ImagePath.add("SikuliTest/patterns/");
        System.out.printf("SikuliTest/patterns/ added?: %s" + "\n", path_add_success);
        for (ImagePath.PathEntry path : ImagePath.getPaths()) {
            System.out.printf("ImagePath: %s\n", path);
        Pattern pattern = new Pattern("pattern.png");

When running from IntelliJ all is fine. When from this .jar (unzipped structure: I get output:

e:\.....\Sikuli_Test_jar>java -jar Sikuli_Test.jar
SikuliTest/patterns/ added?: true
ImagePath: null
ImagePath: null
[error] Image: load: failed: jar:file: /E:/......./out/artifacts/Sikuli_Test_jar/Sikuli_Test.jar!/patterns//pattern.png

Weirdly the "/" gets doubled.

I can provide this test project and .jar if needed.

RaiMan (raimund-hocke) said : #4

Yes, send me the stuff zipped to sikulix---at---outlook---dot---com

RaiMan (raimund-hocke) said : #5

got the stuff - will come back

Can you help with this problem?

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

To post a message you must log in.