[ad name=”AD_INBETWEEN_POST”] Let us see how to create a JAR file using Java’s jar command as well as using Eclipse IDE. The JAR file format is based on the popular ZIP file format. Usually these file are used for archiving and distribution the files and implementing various libraries, components and plug-ins in java applications. Compiler and JVMs (Java Virtual Machine) can understand and implement these formats for java application.
JAR file using Java commands
Following are few commands that can be used to create/view/modify/execute a JAR file using Java command line utilities and JVM.
Create a JAR file
View contents of a JAR file
View contents with detail of a JAR file
Note that we have used v (verbose) option to see the detail of JAR.
Extract content of JAR file
Extract specific file from JAR file
Update a JAR file
Executing a JAR file
Create an executable JAR file
In order to create an executable JAR, one of the classes that we include in our JAR must be a main class.
Create a text file called MANIFEST.MF using any text editor and copy following content in it.
Where MyMainClass is the name of the class that contents main method. Also note that you have to specify fully qualified class name here.
Use following command to create an executable JAR file.
JAR file using Eclipse IDE
Creating JAR file using Eclipse IDE is pretty much easy. Follow the simple steps.
Right click on your project, which you want to create a JAR file of. And select Export from the context menu.
Select JAR file from Java folder and click Next.
Provide the Destination path and click on Finish to create the JAR.