JAR file is the compressed file format. You can store many files in a JAR file. JAR stands for the Java Archive. This file format is used to distribute a set of java classes. This file helps you to reduce the file size and collect many file in one by compressing files. Downloading the files are become completed in very short duration of time because of reducing the file size. You can make the jar file executable by collecting many class file of your java application in it. The jar file can execute from the javaw (Java Web Start).
The JAR file format is based on the popular ZIP file format. Usually these file format is not only used for archiving and distribution the files, these are also used for 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.
For mentioning the product information like vendor name, product version, date of creation of the product and many other things related to the product are mentioned in the manifest file. Such type of files are special which are mentioned in the jar file for making it executable for the application. This file format is to be used for collecting auxiliary files associated with the components.
To perform basic operations for the jar file there has to be used the Java Archive Tool (jar tool). It is provided by the jdk (Java Development Kit). Following are some jar command which are invoked by the jar tool:
Functions Command
-------------------------------
1.creation a jar file
2.viewing contents of a jar file
viewing contents with detail of a jar file
extract all the files of a jar file
extract specific files from the jar file
update jar files
1.running a executable packaged jar file jar cf jar-file-name file-name(s)_or_directory-name
2.jar tf jar-file-name
jar tvf jar-file-name
jar xf jar-file-name
jar xf jar-file-name file-name(s)_from_jar-file
jar uf jar-file-name file-name(s)_from_jar-file
java -jar jar-file-name
/*Creating a JAR file in Java
This section provides you to the creating a jar file through the java source code by using the jar tool command which is provided by the JDK (Java Development Kit). Here, you can learn how to use the jar command, which is used in the dos prompt, in the java source code to perform same operations.
Following program is given for best illustration about using the dos used command in the java source code to perform the appropriate tasks. This program has been used the jar command "jar cf jar-file-name directory-name" in the source code to create a jar file for the given directory. You can also specify the file name(s) to collect it into the jar file format.
Code Description:
Runtime:
Runtime is the class of java.lang.*; package of Java. This class helps application to interface with the environment in which the java application is running.
Runtime.getRuntime():
This method gets the current runtime environment.
Runtime.exec(String[] command):
This method helps you to run the command of that environment in which your java application is running
*/
import java.io.*;
public class CreateJar{
public static void main(String[] args) throws IOException{
if(args.length <= 0){
System.out.println("Please enter the command.");
System.exit(0);
}
else{
Runtime.getRuntime().exec(args[0] + " " + args[1] + " " + args[2] + " " + args[3]);
}
}
}
No comments:
Post a Comment