Java Sikuli program works within Netbeans but fails once built as a Jar

Asked by Nathan Ash-Vie

Hello all,

I have a Java project which processes automation against an insurance system using the Sikuli library. I've set my project up as follows:

• Imported sikuli-ide.jar into the Libraries folder (added to the "Compile" tab within the "Libraries" section of project properties).
• imported the relevant Sikuli functionality within my class hierarchy as needed e.g. "import org.sikuli.script.Screen;".
• App works fine when running from within Netbeans. Attempting to run the finished Jar from the Dist folder I first receive the following errors:

[error] ResourceLoaderBasic: check: No valid libs path available until now!
[action] ResourceLoaderBasic: check: Please wait! Trying to extract libs to jar parent folder: F:/NetBeansProjects/I90AutomationTool/dist/lib/

After a short pause the script appears to start but none of the keystrokes actually function.

Here is a screenshot of the app working when being run from Netbeans: http://i59.tinypic.com/316qgw8.png

When I run the final Jar from the Dist folder the "Keystroke" text field is populated with the above warnings.

I suspect that when the sikuli-IDE is moved to the Dist folder the file path is changing in such a way that the app is not able to import the classes any longer (a bit like if you've ever had to reference images within a Jar using getResource()). Just a hunch.

Any ideas?

Thanks,

Nathan

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#1

The ResourceLoader message only appears on the first run, thereafter no message is displayed but the keystrokes do not start and nothing is output to the [LOG]. Really odd, everything appears to be setup correctly. I tried relogging as I've had problems when moving the sikuli jars/dlls around in the past but it didn't help.

Thanks,

Nathan

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#2

EDIT: accidentally posted the last comment as "Status Solved".

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#3

UPDATE: appears to be the image recognition which is the cause (perhaps linked to how I'm referring to images stored within different packages which get compiled into the JAR). If I add something like scree.type(Key.TAB); outside of the image recognition it works fine from the Dist folder.

Looks like this isn't a Sikuli problem rather more the way image resources are retrieve via the following function:

    public Pattern getPattern(String name) {

        String path = getClass().getResource("/system/model/i90/imgs/" + name).getPath();
        return new Pattern(path);

    }

Works fine in Netbeans from the src folder but fails once compiled to a Jar.

Apologies for wasting anyone's time. Have set to solved.

Thanks,

Nathan

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#4

Plot thickens... It looks like it might be Sikuli again, I've verified the existance of the resource at runtime and the image can be found within the Jar. Does Sikuli not like patterns created from images stored within the app Jar?

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#5

Definitely appears to be a problem with Sikuli accessing images stored within packages of the main compiled Jar. This is the FindFailed message returned by Sikuli:

FindFailed: null
    Line 1671, in file Region.java

Revision history for this message
RaiMan (raimund-hocke) said :
#6

What version of Sikuli?

at least with version 1.0.1 this is possible.

look the javadocs class ImagePath.add
http://nightly.sikuli.de/docs/index.html

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#7

I'm not entirely sure, is there a way to check?

Thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#8

run your project in NetBeans with VM option
-Dsikuli.Debug=3

This should reveal a version info.

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#9

This is what I get using -Dsikuli.Debug=3 (looks like version Sikulix 1.01):

[debug] Screen: initScreens: basic initialization (2 Screen(s) found)
[debug] *** monitor configuration (primary: 0) ***
[debug] Screen 0: S(0)[0,0 1280x1024]
[debug] Screen 1: S(1)[1280,0 1280x1024]
[debug] *** end monitor configuration ***81787
[debug] waiting for P(//whds001/users/Ashvien/NetBeansProjects/I90AutomationTool/build/classes/system/model/i90/imgs/UN002.PNG) S: 0.7 to appear
[debug] Screen.capture: java.awt.Rectangle[x=0,y=0,width=1280,height=1024]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=0,y=0,width=1280,height=1024]
[debug] ResourceLoaderBasic: SikuliX Package Build: 1.0.1 12SEP2013160242
[debug] ResourceLoaderBasic: check: we are running on arch: amd64
[debug] ResourceLoaderBasic: check: using Java at: C:/Program Files/Java/jdk1.7.0_45/jre/
[debug] ResourceLoaderBasic: check: Exists libs folder at location of jar? YES: G:/UW/EDI/Automated Testing Tool/Packages/
[debug] ResourceLoaderBasic: checkLibsDir: G:/UW/EDI/Automated Testing Tool/Packages/libs
[debug] ResourceLoaderBasic: loadLib: WinUtil
[debug] ResourceLoaderBasic: loadLib: Found: WinUtil
[debug] ResourceLoaderBasic: loadLib: Now loaded: WinUtil
[debug] ResourceLoaderBasic: checkLibsDir: Using libs at: G:\UW\EDI\Automated Testing Tool\Packages\libs
[debug] ResourceLoaderBasic: check: Using this as OCR directory (tessdata) too
[debug] ResourceLoaderBasic: loadLib: VisionProxy
[debug] ResourceLoaderBasic: loadLib: Found: VisionProxy
[debug] ResourceLoaderBasic: loadLib: Now loaded: VisionProxy
[debug] P(//whds001/users/Ashvien/NetBeansProjects/I90AutomationTool/build/classes/system/model/i90/imgs/UN002.PNG) S: 0.7 has appeared.
[log] CLICK on L(211,258)@S(0)[0,0 1280x1024]
[log] TYPE "#F3."
[debug] Robot: doType: F3 ( 114 )
[log] TYPE "#ENTER."
[debug] Robot: doType: Enter ( 10 )
[log] TYPE "DRCAR"
[debug] Robot: doType: Shift ( 16 )
[debug] Robot: doType: Shift ( 16 )
[debug] Robot: doType: Shift ( 16 )
[debug] Robot: doType: Shift ( 16 )
[debug] Robot: doType: Shift ( 16 )
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[debug] ResourceLoaderBasic: loadLib: Is already loaded: WinUtil
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[log] TYPE "#TAB."
[debug] Robot: doType: Tab ( 9 )
[log] TYPE "UK"
[debug] Robot: doType: Shift ( 16 )
[debug] Robot: doType: Shift ( 16 )
[log] TYPE "#ENTER."
[debug] Robot: doType: Enter ( 10 )
[log] TYPE "#ENTER."
[debug] Robot: doType: Enter ( 10 )
[log] TYPE "#ENTER."

The above works fine in debug, when run as a Jar the first image check fails:

//whds001/users/Ashvien/NetBeansProjects/I90AutomationTool/build/classes/system/model/i90/imgs/UN002.PNG

The path to the above when run from the compiled Jar as reported by the getPath() function of getResource() is:

file:/F:/NetBeansProjects/I90AutomationTool/dist/I90AutomationTool.jar!/system/model/i90/imgs/UN002.PNG

The above is blank where a resource cannot be found so the fact that getPath() returns the images location suggests it is there in Jar - I can confirm this by opening the Jar in 7-zip and browsing to the file. So it seems to be my getPattern() function stops working when the app is built (or there is some kind of Siluli problem locating the file within the Jar?):

    public Pattern getPattern(String name) {

        String path = getClass().getResource("/system/model/i90/imgs/" + name).getPath();
         return new Pattern(path);

    }

Struggling for ideas as to what it could be.

Thanks for taking the time to reply thus far :)

Nathan

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#10

Could it be something to do with the fact that my NetBeansProjects folder sits within a network drive (//whds001/users/Ashvien)? When run from Netbeans the path is reported using the network mapping name:

//whds001/users/Ashvien/NetBeansProjects/I90AutomationTool/build/classes/system/model/i90/imgs/UN002.PNG

Once compiled the driver letter mapping is substituted:

F:/NetBeansProjects/I90AutomationTool/dist/I90AutomationTool.jar!/system/model/i90/imgs/UN002.PNG

(F:\ being //wsds001/users/Ashvien)

?

Nathan

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#11

It's not the network mapping, I tried substiting F:/ for the actual mapping name, it found the file but FindFailed still raised an exception:

FindFailed: null
  Line 1671, in file Region.java

Any idea what the message is null? Usually FindFailed has a message noting the problem such as the image could not be found, but it's just null.

Thanks,

Nathan

Revision history for this message
RaiMan (raimund-hocke) said :
#12

F:/NetBeansProjects/I90AutomationTool/dist/I90AutomationTool.jar!/system/model/i90/imgs/UN002.PNG

Is an URL pointing to a file inside a jar (does not matter wether mapped or not).

This surely does not work with new Pattern() in 1.0.1 (here only files in the file system outside jars are accepted).

You might try to use the above mentioned ImagePath feature.

If this does not work, then you have to move the image files to the outside at runtime (temp folder) or wait for a useable version of 1.1.0

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#13

There is no ImagePath in my Sikuli-IDE.jar, could that be part of the problem? The JavaDoc notes it should be here:

org.sikuli.script.ImagePath

Here is a screenshot of what I get within org.sikuli.script, you can see ImagePath is not present in the SikuliX 1.01 lib:

http://i60.tinypic.com/9i8fnl.png

Nathan

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#14

Ahah! I think we both replied at the same time, will try separating the images from the Jar.

Thanks for your patience, I'm a Sikuli newb. It's a fantastic lib by the way.

Regards,

Nathan

Revision history for this message
RaiMan (raimund-hocke) said :
#15

ok, sorry, my fault.

Then you only have the other options.

Revision history for this message
RaiMan (raimund-hocke) said :
#16

But you might as well hold your images for the moment (a few days ;-) out of the project completely.

Can you help with this problem?

Provide an answer of your own, or ask Nathan Ash-Vie for more information if necessary.

To post a message you must log in.