Saturday, December 26, 2015

How To Create JAR File in Java and in Ecclipse

JAR files means the output of the Java Archive Tool.
Java Archive Tool:  It is a program that is a part of the J2SE Kit. We must set the path before using Jar command. Here Path means where OS looks to run Programs. so we can created jar files using JAR.EXE utility program from JDK. So to make jar files runnable we first need to create manifest file. Here manifest file is one line text file with a "main-class" directive.

For Example:
main-class: luckyprogramclass


Here is step by step process to create Jar files from command prompt:

Step 1: Start Command Prompt
Step 2: Navigate to the folder that holds to your class files

          c:\cd\luckyprogram

Step 3: set path to include JDK bin.

For Example: c:\luckyprogram>c:\program files\java\jdk 1.5\bin;%path%

step 4:  Compile your class(es):

               c:\luckyprogram>javac*.java

Step 5: create manifest file:

                 c:\luckyprogram>echo Main-class:luckyprogramclass>manifest:txt

Step 6: crate jar file:

                  c:\luckyprogram>jar cvfm luckyprogramclass.jar manifest.txt*.class

step 7: Test your jar

            c:\luckyprogram>luckyprogramclass.jar


To create JAR File in the Eclipse Workbench 

 Step 1:   First we have to select Package Explorer, here we can select optionally pre select one or more java elements to export.

Step 2: we need to select Export either from the menu bar's of File menu or from the context menu. 

Step 3:  In the Wizard Page should have expand the java node  and select JAR file.and then click next.

Step 4:  Select the resources that we want to export in the JAR file Specification page.

Step 5:  Select the appropriate check box to specify  whether we want export generated class files and resources.

Note :  here selected resources exported in this case.

Step 6: You need to click Browse to select a location for the JAR file

Step 7: Select or clear the Compress of the contents of the JAR file check box.

Step 8: Select or clear the Overwrite Existing files without warning check box.

Step 9: here we have two options

Step 10: To create JAR files immediately click Finish

Step 11: Click Next to use the JAR Packaging Options page to set advanced options, create a JAR description, or change the default manifest. 

Step 12: If we want to save the JAR file description, select the Save the description of this JAR in the workspace checkbox. A JAR file description can be used to regenerate a JAR file without using the wizard. 

Step 13: The compiler is able to generate CLASS files even when source contains errors. We have the option to exclude CLASS (but not source) files with compile errors. These files will be reported at the end, if reporting is enabled. 

Step 14: We can choose to exclude CLASS (but not source) files that have compile warnings. These files will be reported at the end.

Note: This option does not automatically exclude class files with compile errors. 

Step 15: We can choose to include the source folder path by selecting the Create source folder structure checkbox. 

Step 16:  Select the Build projects if not built automatically checkbox if you want the export to perform a build before creating the JAR file. 

Step 17: Click Finish to create the JAR file immediately or Next if we want to change the default manifest.

Select 18:If it is not already selected, click the Generate the manifest file button. 

Step 19: We can now choose to save the manifest in the workbench. This will save the manifest for later use. Click Save the manifest in the workspace, then click Browse next to the Manifest file field to specify a path and file name for the manifest. 

Step 20: If we decided to save the manifest file in the previous step and you chose to save the JAR description on the previous wizard page, then you can choose to reuse it in the JAR description (by selecting the Reuse and save the manifest in the workspace checkbox). This means that the saved file will be used when the JAR file is recreated from the JAR description.This option is useful if you want to modify or replace the manifest file before recreating the JAR file from the description. 

Step  21: We can choose to seal the JAR and optionally exclude some packages from being sealed or specify a list with sealed packages. By default, nothing is sealed. 

Step 22:Click the Browse button next to the Main class field to specify the entry point for our applications.

Note: If our class is not in the list, then we forgot to select it at the beginning.   Click Finish. This will create the JAR, and optionally a JAR description and a manifest file.

  



No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...