SUN's Java distribution has an archive tool called jar. The jar tool is a Java application that combines multiple files into a single JAR archive file. The jar tool also compresses files. In addition, it allows individual entries in a file to be signed with a digital signature so that their origin can be authenticated. This is important for authors of Java applets and application which will be sent across a network. See Unix tool jarsigner for signing jar files.
The syntax for the jar tool is almost identical to the syntax for the Unix tar command. See the Unix man page.
% man jar
Here is a simple use of jar to archive all the .java files in a directory.
% jar cvf myJar.jar *.java added manifest adding: Bank.java(in = 1124) (out= 938)(deflated 16%) adding: Customer.java(in = 2235) (out= 661)(deflated 70%) %To retrieve the files from a JAR archive, type the following:
% jar xvf myJar.jar created: META-INF/ extracted: META-INF/MANIFEST.MF extracted: Bank.java extracted: Customer.javaAny file can be in a JAR archive such as images and a ReadMe file.
To create a .jar file which you can run, you need to create a manifest file (MyManifest) which has in it the line
Main-Class: classnamewhere "classname" is the name of your class with the "main" method. Make sure a "Return" is entered after the line.
Then create the .jar file as
% jar cmf MyManifest myJar.jar *.classwhere myJar.jar is name of the new .jar file and *.class is all the class files in the current directory.
To run, type the following:
% java -jar myJar.jarYou may include images such as gifs and jpegs in the runnable file as well. In that case, place all the gif, jpeg, and .class files in one directory and jar that.