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

Main
 - src
        -- Prog.java
        -imgs
                  -- img1
                  -- img2

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-03-03
Last reply:
2017-03-03
RaiMan (raimund-hocke) said : #1

please read:
http://sikulix-2014.readthedocs.io/en/latest/scripting.html#image-search-path-where-sikulix-looks-for-image-files

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
zeOf_ptrdiff_t()I

------------------------

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
der.java:58)
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
.Region
        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[])
     {
         StartQuintiq();
         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;
         try
         {
             if(ImagePath.add(JarFolder))
                 Debug.info("Image Folder in jar at: %s", JarFolder);
             else
                 Debug.error("Image Folder in jar not possible: %s", JarFolder);
             String pwd = "pwdBox.JPG";
             Pattern pwdBox = new Pattern(pwd);
             s.wait(pwdBox, 60D);
             s.click(pwdBox);
             Settings.TypeDelay = 0.0D;
             s.type(null, "CronTab667!", 0);
             s.click("LoginButton.JPG", Integer.valueOf(0));
             s.wait("MainPage.JPG", 120D);
             s.click("ChooseAppointment.JPG");
             s.type("\uE002");
             s.wait("ChooseAppointmentID.JPG");
             s.click("ChooseAppointmentID.JPG");
             s.click("ClearSearch.JPG");
             s.wait("DataLoaded.JPG", 30D);
             s.rightClick("DataLoaded.JPG");
             s.wait("Export.jpg", 30D);
             s.click("Export.jpg");
             s.wait("ExportOK.jpg", 30D);
             s.click("ExportOK.jpg");
             s.waitVanish("ExportWindow.jpg", 30D);
             try
             {
                 Thread.sleep(1000L);
             }

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.