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.

5.11 Bundling a Java Program: Put It in a JAR163$ jar cmf manifest payback.jar net$ ls -latotal 20drwxrwxr-x 3 mschwarz mschwarz 4096 Aug 4 18:19 .drwxrwxr-x 7 mschwarz mschwarz 4096 Aug 4 17:57 ..-rw-rw-r-- 1 mschwarz mschwarz 43 Aug 4 18:17 manifestdrwxrwxr-x 3 mschwarz mschwarz 4096 Jul 28 16:16 net-rw-rw-r-- 1 mschwarz mschwarz 7506 Aug 4 18:21 payback.jarThe opti<strong>on</strong>s to jar tell it what to do. In our case, -c instructs to create aJAR file, -m adds the c<strong>on</strong>tents of the file named in the next parameter to theMETA-INF/MANIFEST file, -f and the next parameter is the filename of the JARfile being created. If we had not specified -f, the JAR file would have beenwritten to standard out and an I/O redirect would be needed, but the resultwould have been the same:$ jar cvm manifest net > payback.jar$ ls -latotal 24drwxrwxr-x 3 mschwarz mschwarz 4096 Aug 4 18:24 .drwxrwxr-x 7 mschwarz mschwarz 4096 Aug 4 17:57 ..-rw-rw-r-- 1 mschwarz mschwarz 43 Aug 4 18:17 manifestdrwxrwxr-x 3 mschwarz mschwarz 4096 Jul 28 16:16 net-rw-rw-r-- 1 mschwarz mschwarz 7506 Aug 4 18:27 payback.jarEverything that follows parameters required by opti<strong>on</strong> letters is c<strong>on</strong>sideredto be a file or directory that is to be added to the JAR file. The opti<strong>on</strong> syntaxfor jar is similar to that for pkzip in the DOS/Windows world and the tarutility in the UNIX world.As elsewhere in this chapter, we are just getting you started. See Sun’sdocumentati<strong>on</strong> for details.5.11.2 Basic jar Operati<strong>on</strong>We have already covered the most comm<strong>on</strong> case, using jar to create a “rolledup”Java applicati<strong>on</strong>. jar has many command opti<strong>on</strong>s besides -c and we’lldocument a few of them.-c-uCreate a JAR file.Update a JAR file—replace updated files, add missing files.

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

Saved successfully!

Ooh no, something went wrong!