Exporting an app with Sikuli - java

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

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.

Related

My Java program won't launch (.exe file)

I have made a GUI based project which consists of 1 main class, multiple Object classes, and resource files (.png and .txt). I have extracted the project as a .jar file (via eclipse) and used that to crease a .exe file (via launch4J). However, when I run the .exe file, it does not launch.
Is it because it does not know which class to run (since there is no manifest file)? What would be some possible fixes?
A manifest (or actually an AndroidManifest.xml) are files for Android systems.
While Android "looks and feels" like Java, it is actually another language. APK files are like a JAR, however, how they are processed and prepared is significantly different, since they are usually DEXed and bit flipped for multiples of 4, they can appear "real jar" for a program, but their instructions are rubish, and have no meaning when executed.
A JAR file is a "Java Archive", and that is another whole concept.
Supposing that the executable was sourced from a correct APK project, then the launch4j should have failed creating the *.exe.
Supposing that the executable was sourced from correct JAR project, then the main is executted (and if its blank, it runs to completion, and ends). It appears as doing nothing, but executes its instructions.
go to run configurations from run menu.---> select java application
---> select the project ---> select your main class ---> save the project ---> clean and build the application.
it seems like you haven't configured a main class for your project.

Generating a runnable .jar file from a libgdx project in intelJ

I basically just spent the whole day trying to get a runnable .jar file from my libgdx project working. In previous projects on a diffrent pc I used to simply navigate my way into the project root folder with cmd and used "gradlew desktop:dist" command. However right now I'm getting error message whenever I try this method.
error
How do I know which folder gradle searches my "tools.jar" file from? I tried even copying it to a few places with no success. I'm using windows OS.
For IDE, I'm using intelJ idea with newest version. I tried to use the "build artifacts" method from IntelJ but what ends up happening with the generated file is that it instantly closes/crashes whenever opened. When running the generated file throught command prompt I get a huge host of errors too numerous to name let alone fix. It seems like it doesen't include the required structures / project folders properly when using artifacts build.
Seems, your environment variable points to the installed JRE(Java Runtime Environment), but has to the Java Development Kit (JDK), because tools.jar is one of the files used by the development tools. You can take a look at the JDK and JRE File Structure to figure out, where is tools.jar located.
So, you have to install JDK(if it was not installed) and make the JAVA_HOME environment variable to points to it.

Java DB Derby and Netbeans 7.1 Build Problems

My application accesses a Derby Database and I have added the Derby.jar to the libraries in the project. It runs fine when compiled and runs perfectly inside the Netbeans environment but once I Build the project, only my application.jar file is in the dist folder. The program will still run but once I try doing anything with the database it hangs.
I tried adding the lib folder containing Derby.jar to the home directory of the application.jar but I still get the same problem.
I'm new to Derby and I'm confused by this, any suggestions?
The answer 1 above does not address the fact the you need to first connect to the database in the service tab of the IDE before you can run your application and that is not possible when you run your application outside the IDE.
This is because you don't also add the project external jar dependencies (such as Derby's jar) to the classpath of your project's executable jar. Basicly, try following their tutorial here:
http://netbeans.org/kb/articles/javase-deploy.html#Exercise_1
the chapter entitled "Running the Application Outside of the IDE" and the one after that.
I haven't used Netbeans in a long while so I don't know if they added this functionality to it now, but with Eclipse you can also make a "fat" executable jar, where all the external jars are packed inside that executable jar, and Eclipse adds a special classloader which makes all this work. It's the option called "Package required libraries into generated jar". Maybe Netbeans lets you do that now too, via some export function or something similar.

Application compiles and builds on Netbeans but not as an independent jar file?

Is it possible that your application compiles and builds flawlessly in Netbeans but when you build it and run it outside of Netbeans you get heaps of Exceptions??! (keeping in mind that the all the libraries and dependencies are ported along with the actual jar file).
I run the followng command
ant -f run
and my program runs flawlessly as it's supposed to, however, where I run the following command to actually build a jar file,
ant -f jar
and when I run the jar file, my application runs but does not perform the tasks it does when it is launched using the first command.
Any ideas why this is happening??! I'm totally lost with this behaviour and can't find why!
If the exceptions are ClassNotFound, then it means that you're missing JARs in the CLASSPATH. NetBeans is sorting it out for you, but when you run outside of it you have to manage it yourself.
keeping in mind that the all the libraries and dependencies are ported
along with the actual jar file
I'm not sure what the word "ported" ends up looking like for you, and without any real information I'm guessing, but your app isn't packaged correctly.
How are you attempting to build your project outside of NetBeans?
Inside NetBeans, if you created the project from within NetBeans, I believe that most of the time NetBeans will create all of its (by default) Ant targets in a file called nbbuild.xml.
Thus, if you're attempting to compile your project outside NetBeans from the command-line (however it exists on your system), you would then need to use the -f nbbuild.xml argument to the ant program to use the NetBeans-generated Ant file. So your command-line might look like this:
ant -f nbbuild.xml compile
Substitute, of course, the target you desire to run for compile in the example above.

Unable to run JAR file on another PC. Possible issue with Environment Variables?

I've built a JAR file and it executes fine on my PC (XP) which has Eclipse installed. It also works on another PC, which also has Eclipse.
I've tried running it on another PC(XP) that does not have Eclipse. Though it contains the JDK and multiple JRE. The JAR file just does not execute by clicking or from the command prompt.
I am not entirely sure, but my best guess is the Environment Variables are not set properly. Here is the error I receive from the command prompt:
Exception in thread "main" java.lang.NoClassDefFoundError: ...
Any help would be appreciated.
It must be a CLASSPATH issue.
The stacktrace should also say which class it failed to find. Once you have that, then find which jar has that class. Then add that jar file to your classpath or add it to the classpath env variable.
This is likely a classpath issue as others have said.
One thing to note is how your jar is constructed. You have a number of options in the dialog for exporting a runnable jar;
Extract classes into jar
Zip dependencies into the jar - creates jar-in-jar-loader.jar inside the jar.
Place jars in a subdirectory next to the jar.
Depending on what you have chosen for this depends on how the jar will behave. If the classes are extracted, dependent classes not in the JDK should be on the classpath. I'd recommend this course of action as it is simpler.
Now, the question is - are you using a dependency on your classpath not in the build dependencies of the eclipse project? If so, it won't be packed with / zipped into / put next to the jar because eclipse doesn't know about it (but java will still find it on your system because it's on the classpath). Also, if you've saved an ANT script and updated the build path in eclipse, eclipse won't update that ANT script - that is generated once only.
Environment variables are not considered when invoking a jar file when clicking on it (equivalent to running javaw -jar your.jar).
I'm pretty sure that it doesn't work on your first PC outside of Eclipse either.

Categories

Resources