Here you will learn how to create executable jar file in eclipse.
An eclipse ide provides facility to convert a project into executable jar file in java. This process is really helpful in case you have development some desktop application in java and want an executable file to directly run the application.
Also Read: How to Add or Import Jar in Eclipse Project
For demonstration purpose I have given simple java program to develop a gui application using swing. You can use this code to test the process of making executable jar in java.
Message.java
package com; import javax.swing.*; public class Message{ Message(){ JFrame f=new JFrame(); JButton button=new JButton("Hello World"); button.setBounds(100, 100, 100, 50); f.add(button); f.setSize(400,400); f.setLayout(null); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new Message(); } }
How to Create Executable JAR File in Eclipse IDE?
1. Open Eclipse IDE and right click on the project from which you want to generate executable jar. Then select Export option.
2. Now choose JAR file under Java and click Next button.
3. Select all the resources that you want to export and also give name and location of destination jar file. After that click Next button.
4. Select the class that contains the main method. Its the entry point from which the jar
will run. You can choose the class by clicking on Browse button.
5. Leave all the settings as it is and click on Finish button to generate the executable jar.
Now you can directly run the jar. If you have used the program that I have given above then after running jar a window will be shown as given below.
Comment below if you are getting any problem to create executable jar file in eclipse ide.
To use the free Worlds Very best graphic feedback: Copy the HTML code from below the graphic image and paste the code on your own blog