A JAR (Java Archive) file is a ZIP format file that bundles Java classes into a single unit. There are two types of JAR file in Java:

    •           Library JAR (normal JAR) files: JARs which are reusable libraries.
    •           Executable JAR files: JARs which can be executed as a standalone Java applications. A main class must be specified when creating this kind of JAR file.

Create a normal JAR file:

Right click on project name in Project Explorer view, select Export… (or select Export… from File menu):

select export

 

In the dialog Export, select Java > JAR file:

select JAR file

 

 

Click Next. In the screen JAR File Specification:

    •           Under section Select resources to export, uncheck the project node, and select src directory (we can select other directories if needed, but the src directory must be selected).
    •           Under section Select export destination, specify path of the JAR file will be exported.

      jar file spec

 

Click Next. In the next screen, we can select an option to save export information so that we can re-create the JAR file later without redoing the previous steps:

    •           Check the option “Save the description of this JAR in the workspace”.
    •           Click Browsebutton to specify path of the description file.

      jar packaging option

 

Click Finish. All class files of the project are exported to a JAR file and a JAR description file is created, under project’s root directory:

jar file exported

Note that the file ends with .jardesc is the JAR description file which stores the information we have specified in the wizard. And we can use it as a shortcut whenever we want to re-export the JAR file.

Right click on the .jardesc file, select Create JAR:

context menu create jar

 

Create an executable JAR file:

Creating an executable JAR file is same as creating a normal JAR file, except it requires to specify a main class. In the screen JAR Packaging Options, click Next will take us to the screen JAR Manifest Specification:

create executable jar file

 

In this screen we can:

    •           Specify the manifest: Select the option Generate the manifest file.
    •           Seal content of the JAR file: select the option Seal JAR.
    •          Select the main class that acts as an entry point to the application: Click Browse button next to the text field Main Class. The dialog Select Main Class displays all classes which have main method. Select the desired class, then click OK:

      select main class 

 

Click Finish, the executable JAR file is created.

 

Other Eclipse Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment

   


Comments 

#5Sachu2020-10-31 02:50
Hey, can you help me with the following requirement.
After you write a simple programme, let's say Hello World, How can we make it executable file in a machine? In other words, when I click a file, the Hello World must come. :)
Thanks a lot
Quote
#4Dianna2017-09-06 23:40
Your style is unique in comparison to other people I have ead
stuff from. I appreciate you for posting when you've got the opportunity, Guess I will just bookmark this blog.
Quote
#3jayshri2015-08-26 04:23
Hi, i have installed eclipse juno. how to create plugin. coz im not able to see the plug-in-development option. Kindly tell me a solution.
Quote
#2sajeet2015-01-14 14:10
hi.....sajeet ..i m sending a eclipse related doc. to ur mail...check it
Quote
#1Kien2014-01-16 01:42
very helpful for me, especial re-export function
Quote