Show Mobile Navigation

Webring

Powered by WebRing.

How to create jar files usinf command line in java

Sachin R Kukale - 02:05
JAR (Java Archive) files in Java are compressed files where all the files related to a specific project/application can be stored. JAR may contain .class, .java and other project/application specific files.
JAR files for a project are mainly created for distribution.
There are two types of JAR files as:
i. Executable JAR files: Executable JAR files are created to provide the fully developed application and mainly it is used to distribute the application among the users.
ii. Non- executable JAR files: Non-executable JAR files are used to provide some library features to other users.
For creating JAR files SUN-microsystems has provided a tool/command called ‘jar.exe’; which is placed in ‘bin’ folder of JDK. To create jar files you must use ‘jar’ command/tool as specified in syntax.
Syntax:
jar
In above command
i. –c -> To create a Jar file.
ii. –f -> To specify the jar file name.
iii. –x ->To extract the Jar file.
iv. –t ->To list the table of contents.
v. –M -> To ignore the manifest information.
vi. –v ->To display the task performed by jar command.
vii. –u ->To update the existing jar file.
viii. –m -> To add the manifest information from some text file.
ix. –e ->To specify the entry for executable jar file.
If you are using the –m option to create then you have to specify the manifesto information from some text file; if you are not providing this information through text file then jar command will not be executed successfully.
Ex:
abc.text
Main-class: (1space) com.jlcindia.A  [press enter without fail]
After specifying the above information you must hit [Enter] key as jar command will ignore the last line from any text file. So by pressing ‘Enter’ key you are making sure that the line entered by you in a command line is not last line of text file.
Also after the ‘Main-class’, which is case sensitive you must provide a colon (;), followed by the ‘one space’ and after that information and at last ‘Enter’.
The attribute value for the ‘Main-class’ must be FullyQualifiedClassName which is having the main method.
If you are using the ‘–e’ from above table then you are not required to create any text file and compiler will implicitly take care of that.
You can execute the executable ‘jar’ file by using the following command:
java –jar
If there is class with swing or awt application then you can execute such a jar file by double clicking on it also.

0 comments:

Post a Comment