Recipe 1.6 Compiling the Source Code Examples from This Book


You want to try out my examples.


Download the latest archive of the book source files, unpack it, edit, and run Ant (see Recipe 1.7) to compile the files.


You can download the latest version of the source code for all the examples in this book from the book's web site, You can get it all as one large file containing all the source code, in a file called javacooksrc.jar, which you should unzip into an empty directory someplace convenient, wherever you like to keep source code. You should then edit the file, specifying the locations of some jar files. Editing and then running ant in this directory first creates a file called darwinsys.jar[4] containing the com.darwinsys API described in Recipe 1.5 (you will probably want to add this file to your CLASSPATH see Recipe 1.4 or to your JDKHOME/jre/lib/ext directory). Ant goes on to build as many of the other examples as it can given the settings in, your Java runtime, and your operating system. The files are roughly organized in per-chapter directories, but there is a lot of overlap and cross-referencing. Because of this, I have prepared a cross-reference file named index-bychapter.html. A mechanically generated file called index-byname.html can be used if you know the name of the file you want (and remember that Java source files almost always have the same name as the public class they contain). The canonical index file, index.html, links to both these files.

[4] If you have a file called com-darwinsys-util.jar, that file contains the old API described in the first edition and will not work with the examples in this book.

If you have JDK 1.3 or 1.4 instead of 1.5, a few files will not compile, but the compiler prints a comment about needing 1.4 or 1.5. And the "native code" examples may not compile at all. Most everything else should compile correctly.

If you're not using Ant, well, you should! But if you can't, or won't, after you've set your CLASSPATH, you should compile what you need. You will need the darwinsys.jar file; you should probably just download it. In some directories you can simply say javac *.java or jikes *.java. But in others, you have to set your CLASSPATH manually; if some files that you need won't compile, you'll have to look in the Ant file build.xml to see what jar files are needed. I no longer provide Makefiles; Ant has simply become the dominant build tool for Java developers.

There may also be times when you don't want to download the entire archive if you just need a bit of code in a hurry so you can access those index files and the resulting directory, for "anyplace, anytime access" on the same web site,

A caveat

One of the practices of Extreme Programming is Continuous Refactoring the ability to improve any part of the code base at any time. Don't be surprised if the code in the online source directory is different from what appears in the book; it is a rare week that I don't make some improvement to the code, and the results are put online quite often.

Java Cookbook
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors: Ian F Darwin

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: