[1.1.1] images not found in runnable jar at root level --- fixed 1.1.1 nightly 2016-12-10

Bug #1647621 reported by RaiMan on 2016-12-06
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

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:


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
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!

RaiMan (raimund-hocke) on 2016-12-06
Changed in sikuli:
status: New → Fix Committed
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.1
RaiMan (raimund-hocke) on 2016-12-09
Changed in sikuli:
importance: High → Critical
summary: - [1.1.1] images not found in runnable jar at root level --- use at least
- one folder level
+ [1.1.1] images not found in runnable jar at root level --- fixed 1.1.1
+ nightly 2016-12-10
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers