Sikulixapi-2.0.4 not working after creating a jar of my Java SWt desktop application

Asked by Kunal Deshpande on 2020-04-21


I have add sikulixapi-2.0.4 jar in my project's build path as external jar and implemented the functionality which I required. Its is working fine as fas a considered running the application in eclipse IDE. But when I export it as jar sikuli doesn't work at all. As I tried to run my jar via commandline to se verbose it enters the loop in while I havw written Sikuli logic but never ever passes the condition and feels like goes in infinite loop nor gives any error. Also I don't think there might be any error in my code. Here is the code below.

----------------- Code starts --------------------
 public String call() throws Exception {
  // ImagePath.add(System.getProperty("user.dir"));
  ImagePath.add(System.getProperty("user.dir") + File.separator
    + "images");
  Screen screen = null;
  try {
   System.out.println("Starting screen capture...");
   screen = new Screen();
   while (true) {
    if (screen.exists(createFullPathOfPatternImages(OKAY_DIALOG_AFTER_EXECUTION)) != null) {
     System.out.println("Dialog loaded!");;
     // Call captureAndSaveScreen function for capturing
     // and saving screenshot.
     captureAndSaveScreen(filePath, fileName);
     // Continue closing process.;
    } else {
     System.out.println("Waiting for dialog...");
     screen.wait(createFullPathOfPatternImages(OKAY_DIALOG_AFTER_EXECUTION), 2.0);
  } catch (Exception ex) {
  return "";
--------------------- Code Ends -------------------------
I have implemented it as a thread to run when the image matches with my desktop application.

Kindly help and suggest the steps required. I am new to Sikuli.


Question information

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

Sorry, I do not understand your problem.

The printout should show, what happens.

Kunal Deshpande (dkunal96) said : #2

I am trying to create a desktop application using java which uses sikulixapi-2.0.4.jar. It works fine when I run the application in my eclipse IDE but when I create a runnable jar file (standalone desktop application using eclipse export option) for my desktop application the Sikuli doesn’t work e.g. the click, keypress and exists commands which were supposed to work doesn’t work when I create a runnable jar file. Can you please guide me so that Sikuli works in my desktop application once a runnable jar is created?

RaiMan (raimund-hocke) said : #3


What a bout the printout, when run from commandline?

add -Dsikuli.Debug=3 to the java command. this should create some SikuliX debug output.

... and put the sikulixapi.jar on the classpath, to be sure it is there.

Kunal Deshpande (dkunal96) said : #4

Okay I will paste the trace here. In classpath you mean in my application classpath in eclipse or one where jdk is installed on my machine?

Kunal Deshpande (dkunal96) said : #5

Is this the correct way if I specify jar file during runtime? javac –classpath C:\dependency\sikulixapi-2.0.4.jar MyApp.Java

RaiMan (raimund-hocke) said : #6

--- classpath at runtime

java -classpath C:\dependency\sikulixapi-2.0.4.jar myApp.jar

--- trace
You have several System.out.println in your code. So if you run your exported jar from commandline, there should be some printout.

Kunal Deshpande (dkunal96) said : #7

--- Classpath issue taht you suggested above.
Error: Could not find or load main class MyApp.jar

# command used as suggested: java -classpath C:\dependency\lib\sikulixapi-2.0.4.jar MyApp.jar

--- Trace after adding -Dsikuli.Debug=3 using command as java -jar -Dsikuli.Debug=3MyApp.jar since the above classpath command didn't work.
[debug] RunTime:temp folder ok: C:\Users\KDeshpa\AppData\Local\Temp\1\Sikulix_1622327834
and when I navigate to it it the folder is empty.

Below is my folder structure from where I am running jar file.

MyApplication >
           images > # This is where images are stored for sikuli
           lib >

Kunal Deshpande (dkunal96) said : #8

I found that I have already added sikulixapi-2.0.4.jar in eclipse library while creating project. Does it still require to specify jar in classpath while executing jar via command line? If yes then its not working for me. Please sugges any alternative steps.

Kunal Deshpande (dkunal96) said : #9

Another info I am executing my sikuli commands using Threads in Java. Hope it doesn't have any issue. Becuase it works fine in eclipse.

Kunal Deshpande (dkunal96) said : #10

Its not even evaluating this "if (screen.exists(createFullPathOfPatternImages(OKAY_DIALOG_AFTER_EXECUTION)) != null)" condition
I am unable to figure it out why its running perfectly in IDE and not after creating runnable jar of the application :( .

Kunal Deshpande (dkunal96) said : #11

Can you please help me?

RaiMan (raimund-hocke) said : #12

--- Its not even evaluating this "if (screen.exists(createFullPathOfPatternImages(OKAY_DIALOG_AFTER_EXECUTION)) != null)" condition

How do you know, that it is not executing the if.... ?

I guess your problem when running the jar is, that the images cannot be located correctly in the file system, in which case the exists() simply does nothing and returns false.

change your code so:

String image = createFullPathOfPatternImages(OKAY_DIALOG_AFTER_EXECUTION)
System.out.println("OKAY_DIALOG_AFTER_EXECUTION is: " + image)
if (screen.exists(image) != null)" condition

This will show you the generated filename.
So you can check, wether it is valid.

Kunal Deshpande (dkunal96) said : #13

I created a path as you said and also checked using new File(image).exists() and its is printing “true” on cmd and also the path is correct.

RaiMan (raimund-hocke) said : #14

again: what about the printout?

Kunal Deshpande (dkunal96) said : #15

It was showing files exits and the filepath was also correct. Is it the issue with corporate systems because I am developing my application in my office.

RaiMan (raimund-hocke) said : #16

It would be much easier if you do not only talk about, what YOU are seeing, but also just paste the print output of your program here together with your source code.

Can you help with this problem?

Provide an answer of your own, or ask Kunal Deshpande for more information if necessary.

To post a message you must log in.