[1.1.1] images not found in runnable jar at root level --- use at least one folder level

Asked by Ricky Ford

Hello all,

I'm currently running Eclipse Mars.2 Release (4.5.2) with the 64-bit jdk1.7.0_79. I am not building a Maven project (that I'm aware of). I simply started a brand new Java Project in Eclipse and imported the Sikuli jar into the project.

I ran the following block of code that helped me to narrow down my setBundlePath options (I think):

String clazz = "testAPI.Test";
String imgFolder = "/imgs";
String img = "test.png";
String inJarFolder = clazz + imgFolder;
if (ImagePath.add(inJarFolder)) {
        Debug.info("Image Folder in jar at: %s", inJarFolder);
 else {
        Debug.error("Image Folder in jar not possible: %s", inJarFolder);
}

Sorry about the formatting above, I'm not sure how to get it to show in blocks.

But any way, that little block of code came from http://sikulix-2014.readthedocs.io/en/latest/scripting.html and led me to create the following two lines of code inside of my Main.java file:

ImagePath.setBundlePath("Main/");
ImagePath.add("Main/");

My current project structure looks like this:

[Main Project Name]
-> src
->-> (default package)
->->-> Main.java
-> resources
->-> image1.png
->-> image2.png
->-> image3.png
->-> etc...

When I run the project in Eclipse, it works perfectly. No issues at all. However, when I export this as a runnable jar (with the Library Handling: option set to "Package required libraries into generated JAR") and then subsequently run it like "java -jar [File.jar]" I get the following errors:

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 Main.main(Main.java:50)
        ... 5 more
Caused by: java.lang.NullPointerException
        at org.sikuli.script.RunTime.init(RunTime.java:635)
        at org.sikuli.script.RunTime.get(RunTime.java:291)
        at org.sikuli.script.RunTime.get(RunTime.java:126)
        at org.sikuli.script.RunTime.get(RunTime.java:316)
        at org.sikuli.script.Region.<clinit>(Region.java:31)
        ... 6 more

I'm assuming this has to do with it not being able to find the images. When I open the jar with 7-zip, all of the images are in the root of the jar as well as "Main.class" -- so I thought I had this thing setup right.

Can anyone help me with this? I'm needing to get this solved drastically as I'm so sick of working with it... Thank you so very much for whatever help I can get!

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Ricky Ford (noxwaste) said :
#1

In case anyone wants the entire command line output when trying to run the jar, this is it:

D:\Users\Ricky\Downloads>java -jar "AppName.jar"
Dec 04, 2016 12:56:57 PM org.jnativehook.DefaultLibraryLocator getLibraries
SEVERE: no entry name specified
Dec 04, 2016 12:56:57 PM org.jnativehook.DefaultLibraryLocator getLibraries
INFO: Library extracted successfully: C:\Users\Ricky\AppData\Local\Temp\JNativeH
ook-3083915753787265699.x86_64.dll (0x63D60AE788E2DA9235AB605F8642D21BB7A58799).

Dec 04, 2016 12:56:57 PM org.jnativehook.GlobalScreen getAutoRepeatRate
INFO: hook_get_auto_repeat_rate [135]: SPI_GETKEYBOARDSPEED: 31.

Dec 04, 2016 12:56:57 PM org.jnativehook.GlobalScreen getAutoRepeatDelay
INFO: hook_get_auto_repeat_delay [149]: SPI_GETKEYBOARDDELAY: 1.

Dec 04, 2016 12:56:57 PM org.jnativehook.GlobalScreen getMultiClickIterval
INFO: hook_get_multi_click_time [208]: GetDoubleClickTime: 500.

Dec 04, 2016 12:56:57 PM org.jnativehook.GlobalScreen getPointerSensitivity
INFO: hook_get_pointer_sensitivity [194]: SPI_GETMOUSESPEED: 10.

Dec 04, 2016 12:56:57 PM org.jnativehook.GlobalScreen getPointerAccelerationMult
iplier
INFO: hook_get_pointer_acceleration_multiplier [163]: SPI_GETMOUSE[2]: 0.

Dec 04, 2016 12:56:57 PM org.jnativehook.GlobalScreen getPointerAccelerationThre
shold
INFO: hook_get_pointer_acceleration_threshold [177]: SPI_GETMOUSE[0]: 0.

Dec 04, 2016 12:56:57 PM org.jnativehook.GlobalScreen getPointerAccelerationThre
shold
INFO: hook_get_pointer_acceleration_threshold [179]: SPI_GETMOUSE[1]: 0.

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 Main.main(Main.java:50)
        ... 5 more
Caused by: java.lang.NullPointerException
        at org.sikuli.script.RunTime.init(RunTime.java:635)
        at org.sikuli.script.RunTime.get(RunTime.java:291)
        at org.sikuli.script.RunTime.get(RunTime.java:126)
        at org.sikuli.script.RunTime.get(RunTime.java:316)
        at org.sikuli.script.Region.<clinit>(Region.java:31)
        ... 6 more

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

what is here in your code:
at Main.main(Main.java:50)

Any progress with the problem?

What version of SikuliX?

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

BTW:
ImagePath.setBundlePath("Main/");

is not supported with this Java class based pointer.
So you should omit it in your code, to be clear.

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

Just checked:
It seems, that you have to insert at least one folder level for the images.
images at the root level do not seem to work yet.

so in your case:

-> resources
->-> images
->->-> image1.png
->->-> image2.png
->->-> image3.png

I will make it a bug.

Revision history for this message
Ricky Ford (noxwaste) said :
#5

At line 50, I'm creating a new instance of Screen:

Screen screen = new Screen();

That could potentially be the problem there with running this thing in the command prompt. However, moving those images one level deeper into resources hasn't seemed to help. Does the folder need to be created as an actual folder, a package, etc.?

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

I created your project structure in IntelliJ IDEA (which does not really matter) and got a jar, that had the Main.class and the images at the jar's root level, which did not work (image not found on image path).

storing the images as mentioned in comment #4 worked for me.

Apart from that, you seem to have another problem, when running the jar from the command line (which I did also when testing and which works for me).

on the command line add -Dsikuli.Debug=3 as Java parameter and check the log for any information that helps.
It crashes in the code part, where we try to evaluate the running jar situation.

Another option is to try with version 1.1.1, since this would allow me, to give you more support and immediately fix any problems.

Please give more information about your environment (system, java, ide, ...)

Revision history for this message
Ricky Ford (noxwaste) said :
#7

Hmm.. I'd like to use 1.1.1, but I can't for the life of me figure out how to install it haha. Am I supposed to compile this thing myself, or what?

Also, I'm running Eclipse Mars.2 Release (4.5.2) with the 64-bit jdk1.7.0_79. I have Windows 8.1 Pro x64 with all updates.

I added that Debug parameter when launching via command line, but it didn't show anything different. Is there a log file somewhere else? Running this script from the command line isn't really that big of a deal. The only reason I tried running it there was because when I launch it as an actual program, it doesn't click anything on the screen like it does when I launch it within Eclipse. So running from the command line isn't necessarily anything we have to troubleshoot, as this will have a very tiny GUI in the end that basically says, "Start" and "Stop".

Revision history for this message
Ricky Ford (noxwaste) said :
#8

Scratch that last message about 1.1.1. I finally got it installed. I didn't notice the installation file on the website.

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

--- but it didn't show anything different
the command has to be this way:
java -Dsikuli.Debug=3 -jar myapp.jar

and should printout additional messages prefixed with [debug] to the commandline window.

In comment #1 I noticed, that you are using JNativeHook in parallel with SikuliX.
It would be worth to test, wether a simple Java Main() jar runs from commandline, that only has one line:
Screen scr = new Screen();

Can you help with this problem?

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

To post a message you must log in.