Unable to find click images when running jar packaged with images from eclipse

Asked by Kamal on 2017-02-10

I think it has been answered earlier, but that solution is not working for me.

I have created an executable runnable jar using eclipse and packaged all of my images in imgs folder which is present inside the jar folder at the root level. But when I run the jat it does not match any images and do not throw any errors as well.

The same code runs perfectly fine from eclipse IDE.

Could some please help.

My project structure is

 - src
        -- Prog.java
                  -- img1
                  -- img2

Question information

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

please read:

especially the note on images in jars

... and be sure to use version 1.1.1 (http://sikulix.com)

Kamal (xs2kamal) said : #2

Hi RaiMan , thanks for coming back.

I downloaded version 1.1.1 and added sikulixapi.jar. From eclipse I am still able to run fine .
But again when I package my Jar using eclipse option 1 ( Extract required libraries into generated jar). I keep on getting the below error. I tried changing JRE from 32 bit to 64 back forth but that also dint help. I am just not able to come around this error.

c:\Jobs\QuintiqAuto>java -jar QuintiqSikuli.jar
java.lang.RuntimeException: Failed to initialize BridJ (java.lang.UnsatisfiedLin
kError: org.bridj.Platform.init()V)
        at org.bridj.Platform.initLibrary(Platform.java:444)
        at org.bridj.Platform.<clinit>(Platform.java:228)
        at org.bridj.BridJ.register(BridJ.java:191)
        at org.sikuli.util.SysJNA$WinKernel32.<clinit>(SysJNA.java:25)
        at org.sikuli.script.RunTime.addToWindowsSystemPath(RunTime.java:1016)
        at org.sikuli.script.RunTime.libsExport(RunTime.java:974)
        at org.sikuli.script.RunTime.init(RunTime.java:719)
        at org.sikuli.script.RunTime.get(RunTime.java:296)
        at org.sikuli.script.RunTime.get(RunTime.java:122)
        at org.sikuli.script.RunTime.get(RunTime.java:321)
        at org.sikuli.script.Region.<clinit>(Region.java:32)
        at BusinessPriorityCodes.main(BusinessPriorityCodes.java:17)
Caused by: java.lang.UnsatisfiedLinkError: org.bridj.Platform.init()V
        at org.bridj.Platform.init(Native Method)
        at org.bridj.Platform.initLibrary(Platform.java:435)
        ... 11 more
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.bridj.Platform.si


If I package my jar using option 2 ( Package required libraries into extracted Jar) , I do not get the above error instead another error.

c:\Jobs\QuintiqAuto>java -jar QuintiqSikuli.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
Caused by: java.lang.ExceptionInInitializerError
        at BusinessPriorityCodes.main(BusinessPriorityCodes.java:17)
        ... 5 more
Caused by: java.lang.NullPointerException
        at org.sikuli.script.RunTime.init(RunTime.java:639)
        at org.sikuli.script.RunTime.get(RunTime.java:296)
        at org.sikuli.script.RunTime.get(RunTime.java:122)
        at org.sikuli.script.RunTime.get(RunTime.java:321)
        at org.sikuli.script.Region.<clinit>(Region.java:32)
        ... 6 more
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org.sikuli.script
        at org.sikuli.script.RunTime$1.run(RunTime.java:498)

Attached is my source code. The error is coming from line : Screen s = new Screen();

public static void main(String args[])
         Screen s = new Screen();
         System.out.println("after launching screen");
         //String mainfolder = "BusinessPriorityCodes";
         String mainfolder = "";
         String imgFolder = "imgs";
         String JarFolder = (new StringBuilder(String.valueOf(mainfolder))).append(imgFolder).toString();
         Settings.MoveMouseDelay = 0.0F;
                 Debug.info("Image Folder in jar at: %s", JarFolder);
                 Debug.error("Image Folder in jar not possible: %s", JarFolder);
             String pwd = "pwdBox.JPG";
             Pattern pwdBox = new Pattern(pwd);
             s.wait(pwdBox, 60D);
             Settings.TypeDelay = 0.0D;
             s.type(null, "CronTab667!", 0);
             s.click("LoginButton.JPG", Integer.valueOf(0));
             s.wait("MainPage.JPG", 120D);
             s.wait("DataLoaded.JPG", 30D);
             s.wait("Export.jpg", 30D);
             s.wait("ExportOK.jpg", 30D);
             s.waitVanish("ExportWindow.jpg", 30D);

RaiMan (raimund-hocke) said : #3

I am not expert with Eclipse jar packaging, but it seems, that you either do not use the right setup for packaging or have any offending stuff in your environment (old versions ...).

Can you help with this problem?

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

To post a message you must log in.