Java Tools for Development and Testing:
jar
Java platforms provide a utility called jar (for Java ARchive), which gives us another way to "package" classes in a single entity and make them available to clients. In this context, one can view the jar utility simply as an alternate to other popular programs such as pkzip or WinZip. However, it is also possible for the java interpreter to read class information directly from a jar file.
Also, in the context of Microsoft's new C# programming language an assembly is defined to be a unit of deployment and execution which is self-describing via a manifest. To which one might respond with the question, "OK, but so is a jar file, isn't it?" Since the answer appears to be yes, this may be one more piece of evidence of the "convergence of technologies".
The following command will put the two class files Foo.class and Bar.class into the Java archive file foobar.jar:
jar cvf foobar.jar Foo.class Bar.class
The following command will show you what's in foobar.jar:
jar tvf foobar.jar
The following command will extract the files in foobar.jar:
jar xvf foobar.jar
The other major thing to remember is that for the java interpreter to access the files in foobar.jar you must have as one component of your classpath the path to foobar.jar (of course) but also the name of the file itself must be included at the end of that path. (Contrast this with the situation for a package, where the classpath need only contain the path(s) to the package file(s) but not the name(s) of any specific file(s).)
A very useful feature of Java is that you can place all the files for your program in a single jar file and then run the program directly from that jar file, and (here's the really wonderful thing) use that same jar file on different platforms. For example, you can build the jar file under Linux, then simply transfer that file to Windows and run it there, either from the command line in a console window or, if it is a GUI application and no console window is desired, simply by double-clicking on it in Windows Explorer.
If we wish to do this, then one of the files in the jar file must be something called a "manifest" file which, in its simplest form, tells the java interpreter which of the class files in the jar file is the one to use to start the program running (i.e., the class file whose name would be supplied at the command line if you were running the program in the "normal" way).
For example, suppose we have a complex "Hello World!" program with several class files, all of which start with 'H'. Here are the two commands that we would need, the first to create, and the second to run, the jar file containing the program:
jar cvmf manifest.mf hello.jar H*class java -jar hello.jar
There are two important things to note:
Main-Class: HelloMain