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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.11 Bundling a Java Program: Put It in a JAR1575.10RETURN TO THE SOURCE:THE JAVA DECOMPILERJava includes a decompiler of sorts called javap. It is sometimes referred to asthe “class file disassembler.” We titled this secti<strong>on</strong> “Return to the Source,” butit is a bit misleading; javap simply provides a way to examine the members andmethods of a compiled Java class 24 even when you do not have its source code.The javap command takes the same access-modifier command-line argumentsas javadoc (-public, -protected, -package, -private) to determinewhich attributes and methods are to be reported. An additi<strong>on</strong>al switch, -c,causes the bytecodes of methods to be reported. For details, see Sun’s documentati<strong>on</strong>for javap. 25Example 5.19 shows what you get if you run javap -c <strong>on</strong> our FetchURLexample.5.11BUNDLING A JAVA PROGRAM: PUT IT INA JARDistributing a Java applicati<strong>on</strong> can be a pain. All but the simplest of applicati<strong>on</strong>swill have many public classes—and since there can <strong>on</strong>ly be <strong>on</strong>e publicJava class per source file, each Java source file becomes a class file, and the elementsof a package name become directory nodes in the path to the class, youend up with a fairly complex collecti<strong>on</strong> of directories and files. Wouldn’t it benice to be able to roll the whole mess up into a single binary file fordistributi<strong>on</strong>?Well, you can. The tool to do the job is called jar, which stands for JavaARchive. 26 The files produced by this utility are called JAR files. The JAR formatis the comm<strong>on</strong> DOS/Windows ZIP file format, with a few special files tosupport some special features we will explain as they come up.24. In Chapter 7 we will introduce gcj, the GNU Compiler for Java, which compiles Java t<strong>on</strong>ative machine code. javap is useless with such a file. It deals <strong>on</strong>ly with JVM bytecodes asdocumented in Sun’s JVM Specificati<strong>on</strong>.25. http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/javap.html26. An abbreviati<strong>on</strong> made up of syllables from words instead of just initials is called aportmanteau. The US Navy is particularly keen <strong>on</strong> them, using terms like COMSURPAC(Commander, Surface Fleet, Pacific), COMSUBLANT (Commander, Submarine Fleet,Atlantic), and so forth. There. Now you can’t claim you didn’t learn anything from this book.

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

Saved successfully!

Ooh no, something went wrong!