Jar
Translation: Cherami
Email: cherami@163.net
Original: http://developer.java.sun.com/developer/techtips/2000/tt0411.html
Have you tried to use the JAR file archive? You may have heard a UNIX tool called "TAR" or tape archive file, which is usually used to back up a set of files. In JDK 1.1 and later, there is a similar tool "jar" or a Java packer. The following is a method of use.
Create a JAR package using the following:
$ jar cf archive.jar file1 file2 ...
After creating the archive package, you can list the contents:
$ jar tf archive.jar
And you can extract the files from it:
$ jar xf archive.jar [file1 file2 ...]
Why is the JAR tools are important? After all, there are many different zip tools for packaging and compress files. Its important use is to bind multiple class files. A set of class files can form a package or library. For example, in Windows 95 or NT, you can say:
ClassPath = "lib1.jar; lib2.jar;"
Another very important usage of it is to optimize the loading of the applet. Consider the simple applet below:
// applet.java
Import java.awt. *;
Import java.applet. *;
Public class applet extends applet {
Public void Paint (Graphics G)
{
String s = message.getInetIntro ("INTRO");
g.drawstring (s, 25, 25);
}
}
It visits a secondary class:
// Message.java
Public class message {
Public Static String GetIntro (String T)
{
IF (t! = null)
Return T;
Else
Return "Hello World!";
}
}
You call this applet with HTML code, for example:
HEAD>