If you are making a java program for windows operating system only then  wouldn’t it be easy to have a exe file for your java program and distribute it to the users and user would find easy to execute your program. Well i guess yes because exe would definetly make easy for users to execute your java programs. So:

Q. How to make an exe file for your java program ?

A. exe4J.

exe4j is a Java exe maker that helps you integrate your Java applications into the Windows operating environment, whether they are service, GUI or command line applications. If you want your own process name instead of java.exe in the task manager and a user friendly task-bar grouping in Windows XP, exe4j does the job. exe4j helps you with starting your Java applications in a safe way, displaying native splash screens, detecting or distributing suitable JREs and JDKs, startup error handling and much more.

Check out the features of exe4J. Download(i would suggest you to download zip archive) the exe4J from here.

Ok now i’ll show you the steps to use exe4J for making exe. So download the exe4J zip archive and extract it to your preference location. Here i’ll be showing you how to create exe file for your java executable jar file. So lets first write a simple swing frame application which will just create a frame.

import javax.swing.*;

public class Test
{
public Test(){
JFrame frame=new JFrame(“test”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,300);
frame.setVisible(true);
}
public static void main(String[] args){
new Test();
}
}

Ok save Test.java it in some folder ( I have saved it in E:/java_programs).

Now open your  command prompt, navigate to the folder where Test.java file is saved and compile the Test.java using command javac Test.java

Now we’ll create a manifest file which will be needed to make an executable jar file. So this is the way you write your manifest file:

Main-Class: Test

First line on your manifest file will be Main-Class:<space>main-class(class file with the main method). then new line<enter>. You have to provide one new line after first line. Then save it as manifest.txt to the same folder where your Test.class file is saved.

Now we’ll create the executable jar file. Syntax is:  jar -cvmf manifest.txt <name of jar file that you will create> class file/package if used

so open up your command prompt, navigate to the folder where Test.class file and manifest file is saved. Then enter command jar -cvmf manifest.txt test.jar Test.class and press enter. Yout executable jar file is created. You can check and test it(java -jar test.jar).

Now executable jar file is ready. So now i’ll show you the steps to make exe from your executable jar file.

STEP 1: Open the folder that u had extracted. Go to bin folder. Double click exe4j launcher. Now exe4j window will open up. Click next.

1

STEP 2: Choose “JAR in EXE” mode. Click next.

2

STEP 3: Now give the name for your application. I have given “app”. Then give the path of the location where you want to save the exe file. I have given the path of location where my class, manifest and jar file are located i.e E:/java_programs. Click next.

3

STEP 4: Now choose your executable type from list of radio buttons. In our case we will choose GUI application. Then give the name of exe file that we are making.  I have provided test. Now check the boxes as shown in the screenshot. And Click next.

4

STEP 5: Now give the name of your main class. In our case its Test. Don’t put the .class extension, just give the name. Now don’t click next.

5

STEP 6: You can see the the gree plus button on above screenshot. Click that and a window will open up. Check the archive radio button above.Now we have to provide the executable jar file to the Archive, so browse the location where your executable jar file is saved. Add it. Click OK. Click next.

6

STEP 7: Now we have to configure the JRE. So provide the minimum jre version and maximum jre version to be used by the user. Then click next.

7

STEP 8: Now we have to configure splash screen (if you want to). I haven’t provided splash screen so i have chosed no splash screen. You can give your choice. Click next.

8

STEP 9: Now we have to configure messages like if you want to give error message when user does not have JRE installed in his/her machine. Click next.

9

STEP 10: Now the last step of the wizard. If you want to save the configuration then click save as. I haven’t saved the configuration so i clicked EXIT. Then it will ask me if i want to save the configuration. Click NO(if you want to save click yes). So Thats it. Done.

10

Now navigate the output folder where u have saved the exe file. In our case we provided the same folder where our jar and class files are located. In below screenshot you can see that test.exe file has been created.

111

Now double click test.exe and message box(“executable was created using evalustion version of exe4J”) will open. Just click ok. Then application will run. In our program we created a frame so frame will get displayed.

13

So thats it. You are off. Your exe has been created. Now you can distribute this exe to windows user. But i f u want to make a cross-platform distributed file then this methos is not recommended. This is for only windows environment.

Thanks.