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.
I wrote a Java GUI program in Netbeans IDE 8.0.1 called SampleChat and used the 'clean and build' function to create a jar file.
I went to the 'dist' directory that Netbeans created and double-clicked the jar file it produced.
A cmd window opened with the following line:
"Error: could not find or load main class.
However, when I opened cmd, changed to the same 'dist' directory and typed the command:
java -jar "SampleChat.jar"
the program ran just fine.
Can I not use Netbeans to create jar files that execute on double-click?
I did not use any pre-existing jar files to complete the program, hence, there was no 'lib' directory or anything like that.
I intend to share programs from a USB stick so it is vital that the only requirement is a JVM, mouse and maybe some fingers to double-click it.
An awkward solution I came up with is to write a batch file that runs the program, but it requires the jar file to not be moved around - screw that.
So how do I make my programs double-click executable?
I guess you are missing to create a manifest file. Therefore it's unknown what your mainclass is. In your java command executed from a terminal you defined the mainclass to execute.
From the tasks you mentioned I guess you are using gradle to build your jar?
Here http://www.gradle.org/docs/current/userguide/java_plugin.html in chapter 23.14.1
an example of an manifest is given.
If you add attributes 'Main-Class': 'com.project.MainClass' it should work.
BR
Assuming that I use NetBeans 7.3 , I created a project that, in a nutshell, receiving as input a set of parameters, it returns as output a print on screen. The project is made up of a number of directories. Each directory contains a class (in file.class form). One of these directory contains an executable in C. I wrote it as the kernel of the Java project.
I built file.jar and I added it as a library in a new project. When I tried to test it, an error message made me realize that the C written program is not was automatically added to file.jar under construction.
One of my first attempt to solve this problem was to manually add the C-executable file. By using the JAR command from the terminal on my Mac, I was able to update the file.jar adding the executable in the right subfolder.
This solution is not served because, moving from project to file.jar, the relative path that leads to the execution of the C-program has changed. So I tried to change this path seeing it from the point of view of file.jar. Yet this attempt was futile.
I defer to those with more experience than me in the packaging and distribution of Java content.
As far as I know, an operating system cannot directly execute an executable that is inside a zip file (which is what a jar file actually is). It has to be first extracted.
So your program could first open its own jar file and extract the executable file into a file on disk, then run that file.
You can create an installer program, to install both the jar file and the executable file to a suitable location on the user's disk.
I'm developing a quite big software for Android in Java (using Eclipse and ADT).
To support my development, I made an own command-line tool that does the following:
Loads and processes certain Java files (from the project of my developed software)
Outputs new Java files to a certain folder (so the input files are retained too) into my project
What the command-line tool does isn't relevant, its output is merely standard Java code (i.e. it's a code generator).
I would like that this command-line tool is automatically called during the build process. In other words, I want that when I'm finished with the manual coding and start the build process (e.g. by clicking "Run..."), the following happens:
The command-line tool is run
The files generated by the command-line tool are included in the build too (i.e. they are compiled exactly as if they were added and coded manually in the Eclipse project).
I'm pretty sure I have to add this program as a "Program" via to the Builder list of the project (see the attached screenshot). My questions:
What position to put it? Should it be the first?
What else do I need to do in order to meet the above requirements? I'm afraid that if the command line tool just writes the .java files to a folder, Eclipse will not see the newly generated files (as they are not added to its project file).
You are on the right track, and it will work fine given these conditions:
Your builder must be at the top, so it can modify the source files before the Java builder is running.
Your Java files must be generated into one of the existing "src" pathes of the project. Java files are not registered in the project, so if you put someting into a source folder of the project, it will be compiled. Eclipse tools like xtext and xtend work the same way.
The refresh option of your builder must be activated. Otherwise the workspace would not know that you created files (as your program works with java.io.File operations, thereby bypassing the workspace API for resources).
I have written a Java program that uses Java swing library. Now I would like to execute this program by double clicking on the executable file on Windows just like any other program with a GUI. How do I do that?
Since it is Java based and has a GUI, the obvious answer is to deploy it using Java Web Start.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
By 'desktop integration' read desktop shortcuts and menu items on supported platforms.
The 2 icons on the right (JotPad & Star Zoom Animation) are both Java based apps., installed using Java Web Start. Since JotPad is sand-boxed, the user will be prompted as to whether to create the shortcut. That choice is not offered for apps. with higher permission levels, so it would make more sense to install/remove the shortcuts and menu items using the IntegrationService - which allows an app. (after prompting the user) to create/remove them at run-time.
There are number of options:
Create an executable jar of your project. for this jar to work you have to have javaw as default application to open it.
Create an exe of your project.
Create a bat file which runs your jar file.
Take a look at this: How can I convert my Java program to an .exe file?
While the others mention excellent choices like creating a native executable, there is another useful method: creating a shortcut.
Right click your desktop, expand the "New" option, and click on "Shortcut".
Type "javaw.exe". Click next.
Name it whatever you want. Click done.
You'll notice the newly created shortcut on your desktop. Right click it and choose "Properties"
In the "Target" textfield, append "-jar path-to-your-jar.jar" where you replace "path-to-your-jar.jar" with the actual path to your jar
You can also now optionally change the icon to whatever icon you want
This shortcut can be pinned to the taskbar and be used from anywhere (considering you provided an absolute path to your JAR).
you need to create exe from the java program.
Creating executable jar files
First, make sure you have installed Java 1.2 or above. This facility is not available in previous versions of Java.
Next, create your working java system. In general, you will want to put it into a package. For this example, I created a trivial HelloWorld application that prints out "Hello World" plus the first command line argument, and placed it into the package "psae". Therefore, the HelloWorld files (HelloWorld.class, HelloWorld.java) were located in the directory psae. I tested the system to make sure it worked before going on to the next step.
In the directory in which the psae is located, created a file called "mainClass". This file contains a single line specifying where the main Class is to be found in the jar file. Note that I use the package specification. Here is the single line:
Main-Class: psae.HelloWorld
Note: make sure you type a carriage return after this line; some windows systems need it and will report a "Failed to load Main-Class manifest attribute" error.
Next, I create a jar file called psae.jar using the "jar" command in Java2. I use the "m" command line argument to specify the manifest file mainClass, which adds information to the jar file on where the main class will be found. Here is the jar command:
bertha:~ > jar cmf mainClass psae.jar psae
Just for fun, and to check what's happened, I print the table of contents for the jar file I just created. Here's the command and its result:
bertha:~ > jar tf psae.jar
META-INF/
META-INF/MANIFEST.MF
psae/
psae/HelloWorld.java
psae/HelloWorld.class
Having successfully created the jar file, I can now invoke java2 on it with the command line argument:
bertha:~ > java -jar psae.jar Philip
Hello World Philip
There are a few projects, like http://jsmooth.sourceforge.net/ and http://launch4j.sourceforge.net/
you can use something like Launch4j.
also look at JSMooth.
Hope it helps
There are two ways. Both involve packaging your code in a .jar.
The first way is to build an actual .exe file using a tool like Launch4j. It will require you to set up things like tell it which class to execute, which icon to use, which JRE is OK, what JRE parameters to use, etc.
The second option is to make the .jar itself executable. You do this by adding a manifest to the .jar. The manifest is a small configuration file that describes the jar. One of the attributes is Main-Class which defines the entry point. In other words, it says which class has the main function that should be called when the user double-clicks the file.
Here's a basic tutorial about manifests: http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
The 2nd option is easier to get going, but users will know what to do with a .exe far more often.
Note that if either approach complains that it can't find the class, make sure to set the classpath manifest attribute to match your project.
If you have an executable jar file, just shift-right click on your file and set it to be opened by javaw. The other option (in case you want to pass in parameters to your application) is to create a .bat file where you spin off your application via java or javaw
Right click to your "project" in eclipse and select "export" then choose "Java->Runnable Jar File" select your project name and finish.
Seems you want to deploy and run the standalone application of swings. Being a java developer you should understand the power of jar files. Those are executable in themselves {so no need to create .exe files :)} .
The below code will help you to create a jar file.
Creating a jar File in Command Prompt
Start Command Prompt.
Navigate to the folder that holds your class files:
C:\>cd \mywork
Set path to include JDK’s bin. For example:
C:\mywork> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%
Compile your class(es):
C:\mywork> javac *.java
Create a manifest file:
C:\mywork> echo Main-Class: NameOfProject >manifest.txt
Create a jar file:
C:\mywork> jar cvfm NameOfProject.jar manifest.txt *.class
Test your jar:
C:\mywork> DanceStudio.jar
After creating a jar just double click on it and you are done.
You have to create an executable jar file. For that you just simply add a META-INF folder to the jar, then add a MANIFEST.MF text file with two lines:
Manifest-Version: 1.0
Main-Class: your.package.YourMainClass
Here's how to run a Java program by RIGHT-CLICKING on it (in other words, from the Windows Explorer context menu). This handy trick is great for beginners who need to test their simple programs on the fly. Works on both Win7 and XP rigs.
[ATTN: Depending on the situation, you may need to remove the package directive from the top of your Java file.]
Step 1. Create a batch file (e.g., RWJ.bat) inside a folder of your choice (say, in C:\Program Files\Java.)
Step 2. Fill RWJ.bat with the following commands (they will work just fine as is with simple classes but you can, of course, tweak them according to your particular needs by specifying compiler / interpreter switches, passing args, adding echo off, removing pause or whatever):
javac %1
java %~n1
pause
The first command passes the full name of your right-clicked file to the Java compiler; the second one strips the file extension and feeds JVM with the class name only.
Step 3. Add the following key to your Registry: HKEY_CLASSES_ROOT\*\shell\Run With Java and then create its command (default value):
C:\Program Files\Java\RWJ.bat %1.
Step 4. Run your Java class by right-clicking it and selecting Run with Java option.
That's all there is to it.
Another way to run Java programs by pointing and clicking is to use AOT compilers. For example, GCC has an entry point named GCJ, which can be used to compile the source code into both byte codes and standard executable file for your particular OS.
And finally, instead ot batch files one can run WSH, etc.