Skip to content
This repository has been archived by the owner on Mar 14, 2018. It is now read-only.

Usage in Java programming

Raimund Hocke edited this page Oct 13, 2015 · 12 revisions

valid for 1.1.0

Run setup with option 2 producing a sikulixapi.jar

Read about new central folder SikulixAppData

Using SikuliX with IDE's like Netbeans, Eclipse

programming with Java or Java based scripting (Jython, JRuby, Scala, Groovy, Clojure, ...)

  • take care, that sikulixapi.jar is in the Java classpath of your project
  • you should leave the Sikuli stuff in one well defined place.
    This avoids odd errors with multiple copies, when updating to new versions.
    In IDE's and other situations always use references/links to the original Sikuli stuff.
  • the native stuff is exported at runtime to a central folder in your SikulixAppData folder
    TAKE CARE on WINDOWS:
    Sikuli adds this libs path to the environment at runtime.
    To avoid library clashes, purge everything from system environment, that has to do with previously used Sikuli versions.
    SikuliX does not need any path entries to the used Java version in the system environment. So purge these too, if not needed for other stuff than SikuliX.

Used Images:
Sikuli searches for image files in the standard in the current working directory (Java property "user.dir") So e.g. in Netbeans you can store images in your project folder and they will be found when simply using "some-image.png". Relative pathnames are possible too (e.g. "images/some-image.png").

Find basic info in the docs
... and tons of more examples in the net - Google is your friend;-)

… but this is a simple test program as well:

import org.sikuli.script.*;
import org.sikuli.basics.Debug;
class Test {
  public static void main(String[] args) throws FindFailed {
    Debug.setDebugLevel(3);
    Screen s = new Screen();
    s.find(s.userCapture().getFile()).highlight(2)
  }
}
  • it gives some more debug output
  • it should ask you to capture something
  • … that in turn is searched on the screen
  • … and highlighted if found

Special information on using Jython in IDEs like Eclipse or running your own Jython

When using Jython e.g. in Eclipse or standalone, the following setup is the easiest and most effective:

  • mind the above information about usage with Java

  • have a reference to sikulixapi.jar in your project's Java class path
    (in your IDE's project's external libraries or simply in Java class path with other setups)
    (do not use sikulix.jar in this case, since the contained Jython might collide with the Jython you want to use)

in your main script at the beginning add:

import org.sikuli.script.SikulixForJython
from sikuli import *

(do not use from sikuli.Sikuli import * any longer)

The first entry is new and adds the path of the Sikuli Jython API to the Python sys.path at runtime (no need to add it yourself, but you might ;-).

from sikuli import * is also needed in every module, that is imported and uses Sikuli features.

To support Jython code completion in the editor of IDE's , you usually need a reference to the Jython sources of Sikuli in your project setup. To no longer have the need to extract the stuff from the jar yourself (Eclipse/PyDev still does not accept references to folders inside of jars), Sikuli will export to the folder SikulixAppData/Lib at runtime.
To support code completion just add to your setup:
<SikulixAppData>/Lib

Be aware Since the undotted functions like click() are only at runtime known to the Jython interpreter (dynamically bound to the object SCREEN being Screen(0)), Eclipse will always tell you, that the name click is unknown - no solution for that with any Eclipse settings.

You simply have to avoid that:

scr = Screen(0) # once at the beginning
# and later use
scr.click()