How to create executable jar file using eclipse


In most of the projects and applications we will use jar files. It can be 3rd party or even internal organization jar files. JAR files are nothing but Java ARchive which will be wrapped with the bundle of .class files, Java files, images, audio or video are any file formats. Its nothing but same as ZIP file which we used in our daily practice. 

By using any unzipping tools we can unwrap JAR files to get files inside. Since mainly its used for .class files and by using obfuscate developers can protect their code and implementation from other users.  

JAR files will be of 2 formats. 
1. Non executable JAR file
2. Executable JAR file

In this tutorial we will how to create executable jar using Eclipse and how to run in Windows. Important for creating executable jar file we need to have at-least single main() method in our project which will be executable. 


STEP - 1: Create new project which we need to implement our functionality  In this demo just we will add 2 numbers as like below. We have created Java Project called AddNumbers and we have class called Add2Numbers and we have implemented our code. Run and test the program once we have implemented. 


creating executable jar file using eclipse


STEP - 2: Right click on Project -> Export -> Java -> Runnable JAR file


creating executable jar file using eclipse


STEP - 3: Click Next and select Project and Class name under Launch configuration: <Add2Numbers - AddNumbers>

 Also enter the folder path and name to save the JAR file in Export destination: D:\\test\AddNubers.jar and click Finish. 

creating executable jar file using eclipse


STEP - 4: Next test your executable jar file from command prompt.


creating executable jar file using eclipse






No comments :

Post a Comment