Monday, April 29, 2013

How to create jar file ?

In this post , we will discuss about how to create a Jar file using Eclipse IDE and once it’s created how to run it in command line(Windows & Unix).

image

So what is JAR ?

In software, JAR (Java ARchive) is an archive file format typically used to aggregate many Java class files and associated metadata and resources (text, images and so on) into one file to distribute application software or libraries on the Java platform.

JAR files are built on the ZIP file format and have the .jar file extension. Computer users can create or extract JAR files using the jar command that comes with a JDK. They can also use zip tools to do so; however, the order of entries in the zip file headers is important when compressing, as the manifest often needs to be first.

Next ? So How to create One ?

To know more about it just follow the steps.

1. Here we taken a simple Arithmetic Application as an Example. Please refer this following post link to know more about it.

http://www.industryvertical.co.in/2013/04/how-to-use-command-line-arguments-in.html

2. Once done with the creation of Java Project , to to export it as an JAR file.

image

image

3. In Java Specification window enter jar destination location and then click next –> JAR Packaging options click next

image

4.  Now Stop in JAR Manifest Specification window and click browse look for a Addition class and select it.

image

image 

5. Once selecting is done you could able to see the com.arithmetic.Addition class in Main Class Field. That’s it !!

You have successfully created your JAR :) !!

image

6. Now just open the bundled JAR archive, look for MANIFEST.MF file and verify the content of it.

image

Final Question ? How to run this exported JAR file ?

Open a Windows Command prompt or Unix Terminal just type the following command inside the AdditionJar.jar location.

Command >> java –jar AdditionJar.jar 1 2

image 

That’s it , in the forthcoming post we will see how to create a WAR, EAR and RAR file using IDE and also using Build Management Tool Ant !!

No comments:

Post a Comment