0

I'm having a problem with the java library sikuli. First I downloaded the sikuli setup jar and executed it. It created sikuli-java.jar and a libs folder (under c:/documents/sikuli). After that I created a project in eclipse, added the jar to the build path and wrote the code. The code worked when I ran it in eclipse. After that I created a runnable jar from it. I ran the runnable jar. It closed when it hit the sikuli code.

I want to export the app as a runnable jar and deploy it, without the users need to install sikuli. Is this even possible?

Also: https://github.com/RaiMan/SikuliX-2014/wiki/Usage-in-Java-programming

take care, that sikulixapi.jar is in the Java classpath of your project

I don't even have a file called sikulixapi.jar.

=======================================

Maybe a quick note, I've created the sikuli-java.jar with option 4 and 6.

edit: Anyone? The application works fine in eclipse but when I export it as runnable jar and run it, as soon as it hits the sikuli stuff it closes. No catch block triggered, although I've surrounded the code with catch(Exception ex). I've configured eclipse like this: https://stackoverflow.com/a/10354759/2815780

Community
  • 1
  • 1
Bosiwow
  • 2,025
  • 3
  • 28
  • 46

1 Answers1

1

This is RaiMan from SikuliX (http://sikulix.com)

-- 1. You currently are using 1.0.1. I recommend to switch to version1 1.1.0, since this installs smoother especially on Windows (no path entry or anything else needed anymore). Since you want to deploy your app to systems not having SikuliX installed, this would make it easier.

-- 2. If you want to run your app on systems not having SikuliX installed, you have to pack a sikulixapi.jar (created with setup for the target system) into your application jar (make a so called fat jar or uber jar) or allow people to download a ready made sikulixapi.jar from somewhere and take care in your application, that sikulixapi.jar is on class path, when your app runs. What makes sense in your case, depends on how you want to publish your app.

-- 3. you say: The application works fine in eclipse but when I export it as runnable jar… Inside Eclipse it takes car, that dependent stuff is on class path. The jar produced in the workspace though is "naked" and need a class path at run time. There is an option, to copy the dependent jar to a lib folder in the workspace. If you do that, your jar will work (though I do not recommend this: sikulix jars should not be moved around but only referenced somehow)

-- 4. you say: No catch block triggered, although I've surrounded the code with catch(Exception ex). If you run your jar from command line saying:

java -jar myapp.jar

it should crash with some unmatched exception (most probably "class not found")

As you already did, you might contact me directly with reference to this post here.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
RaiMan
  • 1,088
  • 8
  • 13
  • first, of all thank you for replying. I've downloaded sikuli 1.1.0. I ran setup an only clicked the second option and let setup do it's work. Now I've got a Libs folder, a Lib folder, a Downlaod folder and sikulixapi.jar. So i guess I should drag and drop the sikulixapi on my eclipse project and add it to the build path. What else should I do? I want everything to be in one big jar (my code + the libraries, so I can just drop the file and run it) Thanks in advance. – Bosiwow Jan 13 '15 at 14:29
  • I've right clicked my project removed all the old sikuli libraries and went to librarie tab. clicked "add external JARS" and navigated to c:\...\Documents\sikuli and selected sikulixapi.jar. So that's the only library I'm using right now. In my eclipse I've got a folder now called "Refrenced Libraries", when I click on the little arrow next to it I see : sikulixapi.jar c:\...\Documents\sikuli . Can I now export it to a runnable jar and deploy it on every system that runs java? – Bosiwow Jan 13 '15 at 14:49
  • I just did the reference library and exported, but I'm getting this error: https://drive.google.com/file/d/0BymG7-nABOfnVGxUQmNzZERtam8/view?usp=sharing I think I've forgotten something :) – Bosiwow Jan 13 '15 at 14:59
  • I really do not recommend, to pack sikulixapi.jar together with your app jar. You should deploy it separately. But in any case, you should never copy sikulixapi.jar into your project - always work with references. The most convenient way would be to use Maven, since then you would not even need setup, just dependencies. And Maven has fine plugins to build fat jars. For examples look into the project on github. – RaiMan Jan 14 '15 at 16:50
  • Okay, I will install maven on my eclipse and try again. Thanks for the update. – Bosiwow Jan 14 '15 at 17:53
  • Apperently maven is already installed on luna eclipse. So what did I do? I right clicked -> new-> maven project. Then it asked me to select an Archetype. I clicked "add Archetype" Filled in group id: com.sikulix ; artifact id: sikulixapi ; version: 1.1.0-SNAPSHOT ; rep url: http://oss.sonatype.org/content/groups/public and added it. Then I choose the newly created archetype. It brought me to a new screen Where I had to type another group id and artifact id. I choose something random (don't know what I should fill in here, I've never used maven) and clicked finished. – Bosiwow Jan 14 '15 at 19:05
  • "Then I got the error: "Unable to create project from archetype [com.sikulix:sikulixapi:1.1.0-SNAPSHOT -> http://oss.sonatype.org/content/groups/public]." Do you have any idea what I did wrong? – Bosiwow Jan 14 '15 at 19:06
  • Yes, Luna has Maven built in. – RaiMan Jan 15 '15 at 11:39
  • Yes, Luna has Maven built in. But as always with Eclipse: the basic Maven stuff is hidden behind complex dialogs, that are hard to understand for beginners. Nevertheless: on this first dialog page when creating a new Maven project at the top click "Create a simple …" and click next. On the next dialog enter a group id like com.mystuff and an artifact id like test1 and click finish. – RaiMan Jan 15 '15 at 12:00
  • Now you will get a project skeleton to work with. The rest has to be done, by double clicking on the pom.xml. Again you get an overwhelming dialog with tons of options. what you then need is the dependencies tab (tabs at the bottom). Now you have to find your own way, since I dislike Eclipse and use Netbeans for the sake of it's good ratio of power to simplicity. – RaiMan Jan 15 '15 at 12:01
  • Okay thank you, will look at it when I'm home; And again thanks a lot. – Bosiwow Jan 15 '15 at 13:26
  • So I've created a maven project in Luna, I moved all the java stuff to src/main/java and my images to src/main/resources/sikuli. After that I looked at the pom.xml from the github example project and setup mine here is what it looks like: http://goo.gl/ubuPRS . After that I ran the code and it worked! It ran from eclipse, so I think maven is configured correctly. (I didn't add any jars myself maven did all the work). Here is what my project layout looks like: http://goo.gl/ELoab4 . i think I need to rewrite the recource line with ImagePath.add(...),What should I write between the parentheses? – Bosiwow Jan 15 '15 at 15:32
  • I've read on the website ImagePath.add("someClass/images"), but I've got no idea what you mean with someclass. Also, if I rewrite that line, can I export it to a runnable jar and will it work? – Bosiwow Jan 15 '15 at 15:33
  • ImagePath.add("someClass/images") --- someClass simply is the name of your main class in the project without .java and images would be sikuli in your case. You should have a look at the java docs too. with this you can simply say new Pattern("2.png").similar(0.85) – RaiMan Jan 15 '15 at 18:05
  • yes this will work when running outside from jar too. – RaiMan Jan 15 '15 at 18:06
  • the relevant Maven plugin is maven-assembly-plugin to produce runnable fat jars containing the dependencies. – RaiMan Jan 15 '15 at 18:08
  • Okay, so i've changed the ImagePath to: ImagePath.add("application.Launcher/sikuli"); Because Launcher alone didn't do the trick (So i thought I would use the full qualified domain name). This worked inside eclipse (Launcher.java contains the main Method and the images are located inside "src/main/resources/sikuli"). Again this all worked inside eclipse, so I exported it to a runnable jar and told it to "copy the required libraries into a sub-folder next to the generated jar" (so no maven plugins). – Bosiwow Jan 17 '15 at 13:51
  • So I ran the exported app and got this error as soon as it hit the lines where it needed the picture: https://drive.google.com/file/d/0BymG7-nABOfnTmR0NzdTXzlSU2M/view , You can see the project hierarchy on the left in this image: goo.gl/ELoab4 ; Do you have any idea why it doesn't work? – Bosiwow Jan 17 '15 at 14:09
  • Thank you for helping me, I've opened a new thread with the image export problem: http://stackoverflow.com/questions/28187543/sikuli-trouble-with-imagepath-java – Bosiwow Jan 28 '15 at 08:20