## Distributing small Java applications (i.e. convert to EXE)

By admin | April 30, 2011

Many times it can be said that it is not very friendly getting a .class file to run. Here is a better way to get them to run - it involves first converting it to an executable .jar and then optionally converting to an executable file on Windows.

Prerequisites:

• Java compiler and JRE
• It is recommended to do this procedure in a separate folder to avoid contamination and interference from other files.

Procedure:

• Compile Java code to generate hello.class (assuming hello.java in this article, replace hello with your application’s name):
javac hello.java
• Add meta file - create file called hello.mf with the following contents (replace hello with your .java name):
Main-Class: hello

Optionally, add the following line if your application depends on other jar files:

Class-Path: (list of jar files here)
• Make an executable jar:
jar cvfm *.jar hello.mf *.class
• At this point you have an executable jar which you can run with any JRE like so:
java -jar hello.jar

. But if you want to generate an EXE for Windows, continue to follow these instructions:

• Set “jar” to hello.jar in the directory where it can be found.
• Set “output file” to hello.exe in the same directory as hello.jar.
• (Optional) Add icon by selecting icon.
• Under “Header” tab, set GUI if your Java application is GUI, otherwise select console.
• (Optional) Under “Single instance” tab, select “Allow only a single instance” if you wish to only allow one copy of your application open at the same time. Type in a random combination of letters and numbers in “mutex name” and type in your application name under “Window title”.
• Set a minimum JRE version under the “JRE” tab (such as 1.3.1).
• Save your configuration if you want to, then click the build icon at the top to build your application.

Topics: Linux | 2 Comments »

### 2 Responses to “Distributing small Java applications (i.e. convert to EXE)”

1. tom Says:
October 9th, 2012 at 2:04 am

hey,
that is clearly explained.But i have a problem
hope you can help.
when i run ” java -jar *.jar”
it says “no main manifest attribute, in *.jar”

and its a standalone applet program i have converted that to application by adding main method in another class and calling it..

and to create jar
here s command i used
“jar -cvfm manifest.mf.txt *.class *.class *.txt”

i don’t know what is the prob..
if you know d solution or if you know the cause of this problem mail me.!!