screen works in IDE run but not in .jar output

Asked by Richard on 2018-05-02

Example code:

    public void testClickAdd(){
        try {
            Screen screen = new Screen();
            Pattern pattern = new Pattern("pics/addToCart.png");

            screen.click(pattern);

        }catch (Exception e){

        }
    }

This code work perfectly when I use IDE to run it. After I output my project as .jar. Run the same code, the click function does not move at all.

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-05-04
Last query:
2018-05-04
Last reply:
2018-05-02
Best RaiMan (raimund-hocke) said : #1

the problem is:
new Pattern("pics/addToCart.png");

Running in the IDE:
the relative path can be converted to an absolute path in the project folder: the imagefile is found

Running the built jar:
the relative path is converted to absolute based on the current working directory: imagefile not found!
... since the imagefile now is inside the jar.

Solution:
use ImagePath feature relative to a classfile:
http://sikulix-2014.readthedocs.io/en/latest/scripting.html#image-search-path-where-sikulix-looks-for-image-files

BTW:
Starting with a new library an empty catch(){} does not make much sense, since it hides exceptions.
In this case the exception would have told you: FindFailed (imagefile not found)

Richard (richardrun) said : #2

Thanks RaiMan, that solved my question.