13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

160Chapter 5The Sun Microsystems Java Software <str<strong>on</strong>g>Development</str<strong>on</strong>g> Kit45 invokevirtual #26 48 iinc 1 151 iload_152 aload_053 arraylength54 if_icmplt 557 returnA JAR file packages a subdirectory and its descendants into a single file. A JavaCLASSPATH specificati<strong>on</strong> may c<strong>on</strong>tain a JAR filename everywhere it mightc<strong>on</strong>tain a directory name. Let’s say you use the GPL’ed Java pers<strong>on</strong>al financeprogram called jgnash and you’ve compiled it from source, so you have a directoryoff your home directory called jgnash/bin. Suppose you run the programby directly invoking java to run the class jgnashMain and you have$HOME/jgnash/bin <strong>on</strong> your CLASSPATH. You could clean up the mess <strong>on</strong> yourhard drive by using the jar command to squash all the files in jgnash/bintogether into a single JAR file, as shown in Example 5.20.Example 5.20 Making a JAR file$ cd ; mkdir jars$ jar cvf jars/jgnash.jar jgnash/binYou could then replace the $HOME/jgnash/bin entry in your CLASSPATHwith $HOME/jars/jgnash.jar. After that you would still run jgnash withexactly the same java command you always did, but now you got rid of thecluttered pile of files.This is <strong>on</strong>ly the most basic purpose of jar, however. Its uses extend wellbey<strong>on</strong>d merely c<strong>on</strong>catenating and compressing collecti<strong>on</strong>s of .class files.5.11.1 Deploying <str<strong>on</strong>g>Applicati<strong>on</strong></str<strong>on</strong>g>sOne of the best uses of jar is to package applicati<strong>on</strong>s for distributi<strong>on</strong>. You canput a large Java applicati<strong>on</strong> into a single file with jar, and by using a manifest(which we are about to discuss) you can nominate the main class to run in thatJAR file. You can then provide a shell script (and a batch file, if you are alsodeploying to Microsoft Windows) that will set the CLASSPATH to point to the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!