3.5 Java Archive (JAR) (Web hosting companies) Files Java archive files

3.5 Java Archive (JAR) Files Java archive files (JAR files) are Java’s suitcases. They are the standard and portable way to pack up all of the parts of your Java application into a compact bundle for distribution or installation. You can put whatever you want into a JAR file: Java class files, serialized objects, data files, images, sounds, etc. As we’ll see in Chapter 20, a JAR file can carry one or more digital signatures that attest to the integrity and authenticity of that data. A signature can be attached to the file as a whole or to individual items in the file. The Java runtime system understands JAR files and can load class files directly from an archive. So you can pack your application’s classes in a JAR file and place it in your CLASSPATH. You can do the equivalent for applets by listing the JAR file in the ARCHIVE attribute of the HTML tag. Other types of files (data, images, etc.) contained in your JAR file can be retrieved using the getResource( ) method. (described in Chapter 10). Therefore, your code doesn’t have to know whether any resource is a plain file or a member of a JAR archive. Whether a given class or data file is an item in a JAR file, is an individual file on the class path, or is located on a remote applet server, you can always refer to it in a standard way, and let Java’s class loader resolve the location. 3.5.1 File Compression Items stored in JAR files may be compressed with ZLIB[1] compression. JAR files are completely compatible with the ZIP archives familiar to Windows users. You could even use tools like pkzip to create and maintain simple JAR files. But jar, the Java archive utility, can do a bit more. [1] See http://www.simtel.net/pub/pd/2530.shtml and RFC 1950. Compression makes downloading classes over a network much faster. A quick survey of the SDK distribution shows that a typical class file shrinks by about 40 percent when it is compressed. Text files such as arbitrary HTML or ASCII containing English words often compress by as much as 75 percent to one-quarter of their original size. (On the other hand, image files don’t get smaller when compressed; both of the common image formats have compression built in.) Compression is not the only advantage that a JAR file has for transporting files over a network. For an application with many components, the amount of time it takes to transport all of the parts may be less significant than the time involved in setting up the connections and making the requests for them. This is especially important for applets loaded via the Web. The typical web browser has to make a separate HTTP request for each class or data file. An applet comprising 100 classes, for example, would require at least 100 separate trips to the web server to gather all its parts. Placing all the classes in a single JAR file enables them to be downloaded in a single transaction. Eliminating the overhead of making HTTP requests is likely to be a big savings, since individual class files tend to be small, and a complex applet could easily require many of them. 3.5.2 The jar Utility The jar utility provided with the SDK is a simple tool for creating and reading JAR files. Its user interface isn’t friendly; it mimics the Unix tar(tape archive) command. If you’re familiar with tar, you’ll recognize the following incantations: jar -cvf jarFilepath [ path ] [ .. . ] Create jarFile containing path(s)
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services

Leave a Reply