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:

https://i.imgur.com/rTxqZec.png

And the code is:

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

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

null
/C:\(...)\patterns/

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

null
null

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

This is the .jar structure when I unzip it:

https://i.imgur.com/QY8CCDG.png

Thanks for any help.

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2020-10-22
Last reply:
2020-10-23
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: https://i.imgur.com/kILFr1e.png) 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.