There are two ways to create the executable jar in java
1. Using eclipse ide
2. Using command prompt by using specific commands
Suppose we have awt/spring based java file i.e JavaHungry.java . Our aim is to convert this file from .java extension to .exe file .
We will first start with Creating a New Runnable JAR File using eclipse ide .
1. Our file JavaHungry.java will look like this in eclipse
1. Our file JavaHungry.java will look like this in eclipse
2. Go to the File option located top-left in the menu bar in the eclipse
3. Select export option from the file menu
4. Expand the Java node and select Runnable JAR file. Click Next
5. In the Runnable JAR File Specification page, select a 'Java Application' here "JavaHungryProject" launch configuration to use to create a runnable JAR
6. In the " Export destination " field browse/choose the location where your new executable jar file will be created . Select an appropriate library handling method .
Thats it , it will create the executable jar in the desired location .
The above method is using eclipse ide , now we will create an executable jar file using command prompt
We are using the same awt/spring based java file i.e JavaHungry.java
1. We need to create a manifest file i.e " manifest.txt "
manifest.txt
Main-Class: JavaHungry
Mandatory : Manifest file should end with the new line character .Main-Class: JavaHungry
Here Main-Class is the entry gate of the jar file (which we are going to create) , when anyone click on the executable jar file , JavaHungry main() method will be launched .
2. So we need to create the jar file , so we should always put manifest.txt and JavaHungry.class together .
So in computer directory it will look like
C:\java\JavaHungry.class
C:\java\manifest.txt
C:\java\JavaHungry.class
C:\java\manifest.txt
So the following command needs to be executed to create the executable jar of JavaHungry class file .
jar -cvfm JavaHungry.jar manifest.txt *.class
If you have any doubts then please express it in the comments .