A Jar file is essentially a collection of files (mostly archives of java classes) in one file,
similar to a ZIP file. A Jar file facilitates the packaging of applications into one file.
In addition to the Java class files and resources, a Jar file can contain a META-INF directory. The most
important file in this directory is Main-Class: classname
in the manifest file specifies the class that gets
executed first.
To run a Jar file at the command line, enter the following command:
java -jar jar-file
When using a GUI, you can also simply double click the Jar file icon.
To compile a Java file and include a Jar file, enter the following command line:
javac -classpath jar-file java-file
For multiple JAR files, separate the jar-files with semicolons, as follows:
javac -classpath jar-file1;jar-file2;jar-file3 java-file
Some rules to note:
To include a Jar file when running a compiled java file, enter the following command:
java -classpath jar-file class-file
To create a Jar file, enter the following command:
jar cf jar-file input-files
For example, if you want to make a
jar cf C.jar A.class B.class